Thursday, December 15, 2011

Refresh UpdatePanel on postback, using JavaScript in Asp.net


in .aspx page

<asp:ScriptManager ID="ScriptManager1" runat="server" />

<div id="Container" onclick="__doPostBack('UpdatePanel1', '');">
<asp:UpdatePanel runat="server" ID="UpdatePanel1" OnLoad="UpdatePanel1_Load"> <ContentTemplate> <asp:Label runat="server" ID="Label1" /> </ContentTemplate> </asp:UpdatePanel>
    <p>
        <asp:Button ID="
Button1
" runat="server" Text="Button" /> </p>
        <asp:Label runat="server" ID="Label2" />

in .cs page

protected void UpdatePanel1_Load(object sender, EventArgs e)
{
  Label1.Text = DateTime.Now.ToString();
}

protected void Button1_Click(object sender,EventArgs e)
{
   Label2.Text = DateTime.Now.ToString();
}


output

On Button click updatepanel get postback first
(display Label1.Text first) on second time Click (Label2.Text value get display)


No comments:

Post a Comment