Got a big issue here with buttons inside an updatepanel. The button fires its normal OnClick function (which is added through the attribute "OnClick"), but when this function is fired, the "Page_Load" function is also automatically fired, when a panel in an .aspx file is updated... Hence; the update do happen, but since it is only the updatepanel is rendered again, the update do not show for the user, but I know it happened, I do not want that. :)
1. A masterpage with the content:
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>2. A content page to the newly created masterpage:<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<asp:ScriptManager runat="server" ID="SCM" EnablePartialRendering="true"></asp:ScriptManager>
<asp:Button ID="btnUpdate" Text="Update" runat="server" onclick="btnUpdate_Click" />
<asp:Label runat="server" ID="lblMaster" BackColor="LightGreen"></asp:Label>
<asp:UpdatePanel runat="server" ID="up1" UpdateMode="Conditional">
<ContentTemplate>
<asp:Button ID="btn1" Text="Btn1" runat="server" onclick="btn1_Click" />
<asp:Label runat="server" ID="lbl11"></asp:Label>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btn1" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
<br /><br />
<asp:UpdatePanel runat="server" ID="up2" UpdateMode="Conditional">
<ContentTemplate>
<asp:Button ID="btn2" Text="Btn2" runat="server" onclick="btn2_Click" />
<asp:Label runat="server" ID="lbl22"></asp:Label>
</ContentTemplate>
<Triggers><asp:AsyncPostBackTrigger ControlID="btn2" EventName="Click" /></Triggers>
</asp:UpdatePanel>
</asp:Content>
3. Code behind (C#) to the newly created content page protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
lblMaster.Text = "Master.aspx Loaded: " + DateTime.Now.ToLongTimeString();
lbl11.Text = "UpdatePanel 1 : ";
lbl22.Text = "UpdatePanel 2 : ";
}
else
{
lblMaster.Text += " Updated? " + DateTime.Now.Second;
}
}
protected void btnUpdate_Click(object sender, EventArgs e)
{
}
protected void btn1_Click(object sender, EventArgs e)
{
lbl11.Text += DateTime.Now.Second + " ";
}
protected void btn2_Click(object sender, EventArgs e)
{
lbl22.Text += DateTime.Now.Second + " ";
}The problem in detail:Click "button1" and the first updatepanel updates.
Click "button2" and the second updatepanel updates.
Now click the third button "Update" and see that the label outside the two updatepanels, has also been "updated" (but not displayed), when we clicked button1 and button2.
How can I fix this "issue"? Is it possible? The "Update?" text should only be written to the label as many times as we have clicked the button "btnUpdate"...
ed: What I've tried:
Adding in the page_load " SCM.RegisterAsyncPostBackControl(btn1);", did not work!
Of course I can change the "event" from "Page_Load" to "Page_Init", but I need the Page_Load function there.
-> of course I can create a session variable to make sure the function calls in Page_load() is not triggered when a button in a updatepanel is clicked
->-> but still, I want to refuse/remove the Page_Load(); call when a button inside a .aspx file is clicked! :)
Edited by ManyTimes, 12 May 2010 - 12:38 PM.


Sign In
Create Account


Back to top









