Update from One UpdatePanel Elements to Another by Programmatically in ASP.NET

No.of Views816
Bookmarked0 times
Downloads 
Votes0
By  jalpesh   On  30 Dec 2010 10:12:52
Tag : ASP.NET , General
In this snippet I will explain how to update one updatepanel elements from updatepanel content by programmatically. Let’s say sometimes you have more than one update panel in your page in that time you may have to update one textbox within the first update from second update button.
emailbookmarkadd commentsprint

Images in this article missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at info@codegain.com

 

Introduction

In this snippet I will explain how to update one updatepanel elements from updatepanel content by programmatically. Let’s say sometimes you have more than one update panel in your page in that time you may have to update one textbox within the first updatepanel  by button,which exists in second updatepanel.

Here is the scenario. 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.

Html Code

<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>

Here comes magic!!. Lots of people don’t know that update panel are providing the Update method from which we can programmatically update the update panel elements without post back. Below is code for that.

C# Code

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

That’s it here I have updated the firstUpdatePanel from the code. Hope you liked it.Happy Programming.

 
Sign Up to vote for this article
 
About Author
 
jalpesh
Occupation-Software Engineer
Company-DotNetJaps
Member Type-Expert
Location-India
Joined date-08 May 2010
Home Page-http://www.dotnetjalps.com
Blog Page-http://www.dotnetjalps.com
I am jalpesh vadgamaa an Microsoft MVP for Visual C# and BrainBench Certified ASP.NET Developer having experience of five year in Microsoft .NET Technology.I am working as Project Leader in Mid Size company.My work area comprises of Enterprise Level projects using ASP.NET and other Microsoft .NET Technologies.Please feel free to contact me for any queries via posting comments on my blog I will try to reply as early as possible.
 
 
Other popularSectionarticles
    Auto Growing TextBox or TextArea in ASP.NET
    Published Date : 08/May/2010
    In this code snippet, you will learn how to bind DropdownList within the ListView in ASP.NET. The ListView is powerful control and fully customizable using templates.
    Published Date : 10/Oct/2010
    In this codesnippet, i will show How to Delete Row in GridView using JQuery in ASP.NET.
    Published Date : 20/Jul/2011
    In this snippet, I will show how to format a cell and apply style in gridview using JQuery. Sometimes we may need to apply the format for a particular cell based on the cell value; it can be done in within DataRowBound event in asp.net.
    Published Date : 05/Jan/2011
    In this snippet I will explain how to add controls dynamically in asp.net and register events for the controls and make it work events perfectly. Last week I have read the forums many readers asking about add controls dynamically in asp.net giving problems and also it not working properly with events
    Published Date : 03/Jan/2011
Comments
By:AjayDate Of Posted:4/11/2012 9:06:33 AM
Update from One UpdatePanel Elements to Another by Programmatically in ASP.NET
helpful
Leave a Reply
Title:
Display Name:
Email:
(not display in page for the security purphase)
Website:
Message:
Please refresh your screen using Ctrl+F5
If you can't read this number refresh your screen
Please input the anti-spam code that you can read in the image.
^ Scroll to Top