Answered by:
Update panel - multiview - controls not getting fired

Question
-
User-73514677 posted
HI,
I am using ASP.NET 4.0 and i have placed a update panel. The page has 2 views.
I have button and dropdown events in the views. I have used the below code:
<asp:UpdatePanel ID="upd1" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="true"> <ContentTemplate> <asp:MultiView ID="Mul1" runat="server" ActiveViewIndex="0"> <asp:View ID="View1" runat="server"> <table> <tr> <td> <asp:ImageButton ID="Img1" runat="server" ImageUrl="/images/Submitn.png" OnClick="Img1_Click" /> </td></tr> <tr> <td > <asp:DropDownList ID="ddl1" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddl1_SelectedIndexChanged"> </asp:DropDownList> </td></tr> </asp:View> <asp:View ID="View2" runat="server"> </asp:View> </asp:MultiView> </ContentTemplate> </asp:UpdatePanel>
The button events and dropdown events are not getting fired. If I remove the update panel, then events are firing.
How to fix this?
Thanks
Sunday, January 24, 2016 9:35 AM
Answers
-
User-2057865890 posted
Hi venkatzeus,
Take a look at Introduction to the UpdatePanel Control
This topic describes how to add partial-page update support to a Web page by using two Microsoft Ajax server controls: the ScriptManager control and the UpdatePanel control.
<%@ Page Language="C#" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> protected void Button1_Click(object sender, EventArgs e) { Label1.Text = "Refreshed at " + DateTime.Now.ToString(); } </script> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Untitled Page</title> <style type="text/css"> #UpdatePanel1 { width:300px; height:100px; } </style> </head> <body> <form id="form1" runat="server"> <div style="padding-top: 10px"> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <fieldset> <legend>UpdatePanel</legend> <asp:Label ID="Label1" runat="server" Text="Panel created."></asp:Label><br /> <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /> </fieldset> </ContentTemplate> </asp:UpdatePanel> <br /> </div> </div> </form> </body> </html>
Best Regards,
Chris Zhao
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, January 25, 2016 10:05 AM
All replies
-
User-1902643333 posted
Everything goes fine with me, plz check this:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="SampleWeb.Default" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> </head> <body> <form id="form1" runat="server"> <div> <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager> <asp:UpdatePanel ID="upd1" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="true"> <ContentTemplate> <asp:MultiView ID="Mul1" runat="server" ActiveViewIndex="0"> <asp:View ID="View1" runat="server"> <table> <tr> <td> <asp:ImageButton ID="Img1" runat="server" ImageUrl="/images/Submitn.png" OnClick="Img1_Click" /> </td> </tr> <tr> <td> <asp:DropDownList ID="ddl1" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddl1_SelectedIndexChanged"> <asp:ListItem Text="Item1" Value="1" Selected="True"/> <asp:ListItem Text="Item2" Value="2"/> </asp:DropDownList> </td> </tr> </asp:View> <asp:View ID="View2" runat="server"> </asp:View> </asp:MultiView> </ContentTemplate> </asp:UpdatePanel> </div> </form> </body> </html>
using System; using System.Web.UI; namespace SampleWeb { public partial class Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void ddl1_SelectedIndexChanged(object sender, EventArgs e) { ScriptManager.RegisterStartupScript(this, GetType(), "msg", "alert('Dropdownlist');", true); } protected void Img1_Click(object sender, ImageClickEventArgs e) { ScriptManager.RegisterStartupScript(this, GetType(), "msg", "alert('OK');", true); } } }
Sunday, January 24, 2016 10:41 AM -
User-73514677 posted
HI,
Thanks for the reply.
Is there anything else which need to be added? This is not working. Is there any other way?
Thanks
Sunday, January 24, 2016 1:18 PM -
User-2057865890 posted
Hi venkatzeus,
Take a look at Introduction to the UpdatePanel Control
This topic describes how to add partial-page update support to a Web page by using two Microsoft Ajax server controls: the ScriptManager control and the UpdatePanel control.
<%@ Page Language="C#" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> protected void Button1_Click(object sender, EventArgs e) { Label1.Text = "Refreshed at " + DateTime.Now.ToString(); } </script> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Untitled Page</title> <style type="text/css"> #UpdatePanel1 { width:300px; height:100px; } </style> </head> <body> <form id="form1" runat="server"> <div style="padding-top: 10px"> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <fieldset> <legend>UpdatePanel</legend> <asp:Label ID="Label1" runat="server" Text="Panel created."></asp:Label><br /> <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /> </fieldset> </ContentTemplate> </asp:UpdatePanel> <br /> </div> </div> </form> </body> </html>
Best Regards,
Chris Zhao
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, January 25, 2016 10:05 AM