Monday, February 21, 2011

Programmatically updating one update panel elements from another update panel elements

 There are two update panels in my html code in first update panel there is textbox hello world and another update panel there is a button called btnHelloWorld. Now I want to update textbox text in button click event without post back. But in normal scenario It will not update the textbox text as both are in different update panel. Here is the code for that.



<form id="form1" runat="server">
       <asp:ScriptManager ID="myScriptManager" runat="server" EnableCdn="true"></asp:ScriptManager>
       <asp:UpdatePanel ID="firstUpdatePanel" runat="server" UpdateMode="Conditional">
           <ContentTemplate>
               <asp:TextBox ID="txtHelloWorld" runat="server"></asp:TextBox>
           </ContentTemplate>
       </asp:UpdatePanel>
       <asp:UpdatePanel ID="secondUpdatePanel" runat="server" UpdateMode="Conditional">
           <ContentTemplate>
               <asp:Button ID="btnHelloWorld" runat="server" Text="Print Hello World"
                   onclick="btnHelloWorld_Click" />
           </ContentTemplate>
       </asp:UpdatePanel>
</form>



protected void btnHelloWorld_Click(object sender, System.EventArgs e)
      {
          txtHelloWorld.Text = "Hello World!!!";
          firstUpdatePanel.Update();
      }

No comments :

Post a Comment