troubleshooting Question

Why is the asp:UpdatePanel not changing the value of my ASP:Textbox when the textbox is updated from Codebehind?

Avatar of Je Vught
Je VughtFlag for United States of America asked on
JavaScript.NET ProgrammingC#ASP.NETAJAX
5 Comments1 Solution22 ViewsLast Modified:

My scheme:

  • I have a label along with a number of textboxes loaded inside an asp:Updatepanel. These controls are initially loaded with values from an SQL database. These values are based on the initial index passed to the page.
  • Additionally the page contains a gridview which contains a list of "contacts".
  • The idea is that if the user selects a contact from the gridview, the index is used to re-query the SQL db. This function returns a datatable which is used to populate the above mentioned textboxes with the selected contacts data - name, address, emails, etc. The user can then modify the textboxes as necessary.
  • At present, I'm using a asp:timer to trigger the updatepanel when a different contact is selected (though I'd welcome a more elegant trigger solution).

When the page is first loaded, the label and all the textbox controls are populated without issue.

The problem: When subsequent contacts are selected, ONLY the label value changes - NOT the textbox values.

What I've tried:

  • If I disable the timer/trigger, then even the label is not updated when a record is selected in the gridview. This seems to indicate that the timer/trigger is effective (when enabled) as an AsyncPostBackTrigger
  • For the textboxes, I've tried variations of how to assign the textbox values (e.g. Textboxt1.text = value;   TextBox1.Attributes.Add("value", value1);
  • Additionally instead of using an asp:Textbox, I've tried using: <input type="text"  id="TextBox1" runat="server" />

Is what I'm trying to do even possible - what am I missing?

   <asp:Timer runat="server" ID="ContactsTimer" Interval="100" Enabled="false" OnTick="ContactsTimer_Tick" />
   <asp:UpdatePanel ID="upnlContacts" runat="server" UpdateMode="Conditional" >  
         <asp:Label ID="lblContactAccountID" runat="server"/>
         <asp:TextBox ID="txtContactFirstName" runat="server"/> 
<%--edit: also tried:
            <input type="text"  id="txtContactFirstName" runat="server" />--%>
         <asp:AsyncPostBackTrigger ControlID="ContactsTimer" EventName="Tick" />

Open in new window

private void LoadSelectedContact(int personID)
      DataTable dt = GetProfileContacts(personID, true);
      if (dt.Rows.Count > 0)
         foreach (DataRow row in dt.Rows)
            lblContactAccountID.Text = row["PersonID"].ToString(); 
            txtContactFirstName.Text = row["FirstName"].ToString();

// edit: also tried the below without success
//            string FirstName = row["FirstName"].ToString();
//            txtContactFirstName.value= FirstName;
//            txtContactFirstName.Attributes.Add("value", FirstName);

            // ...
            ContactsTimer.Enabled = true;

   protected void ContactsTimer_Tick(object sender, EventArgs e)
      ContactsTimer.Enabled = false;

Open in new window

Edit: I added (above) an example of the '<input type="text" ...  ' that I've tried without success. Below is the Gridview markup and the associated codebehind:

<asp:GridView ID="gvContacts" runat="server" CssClass="table table-striped solid-top" AutoGenerateColumns="false"
   DataKeyNames="PersonID" OnRowCommand="gvContacts_RowSelected">
      <asp:BoundField DataField="PersonID" />
      <asp:TemplateField HeaderText="Name" ItemStyle-Width="10%" ItemStyle-HorizontalAlign="Center">
            <asp:LinkButton runat="server" CommandName="Selected" CommandArgument="<%# Container.DataItemIndex %>"><%#Eval("LastName")%></asp:LinkButton>
            <asp:LinkButton runat="server" CommandName="Selected" CommandArgument="<%# Container.DataItemIndex %>"><%#Eval("FirstName")%></asp:LinkButton>
      <asp:TemplateField HeaderText="Action" ItemStyle-Width="10%" ItemStyle-HorizontalAlign="Center">
            <asp:ImageButton runat="server" ImageUrl="~/Images/icon_pencil.png" ToolTip='<%# "Edit Profile for "  + Eval("firstname") + " " + Eval("lastname") %>' CommandName="Edit" CommandArgument="<%# Container.DataItemIndex %>" />

Open in new window

protected void gvContacts_RowSelected(object sender, GridViewCommandEventArgs e)
   GridViewRow row;
   if (e.CommandSource.ToString() == "System.Web.UI.WebControls.ImageButton")
      row = (GridViewRow)((ImageButton)e.CommandSource).NamingContainer;
      row = (GridViewRow)((LinkButton)e.CommandSource).NamingContainer;
   int personID = Int32.Parse(row.Cells[0].Text);
   switch (e.CommandName)
      case "Selected":
      //case "Edit" ...

Open in new window

David H.H.Lee
Digital Marketing (Hospitality)
Log in to continue reading
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform for $9.99/mo
View membership options
Unlock 1 Answer and 5 Comments.
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
The Value of Experts Exchange in My Daily IT Life

Experts Exchange (EE) has become my company's go-to resource to get answers. I've used EE to make decisions, solve problems and even save customers. OutagesIO has been a challenging project and... Keep reading >>


Owner of Outages.IO
Phoenix, Arizona, United States
Member Since 2016
Join a full scale community that combines the best parts of other tools into one platform.
Unlock 1 Answer and 5 Comments.
View membership options
“All of life is about relationships, and EE has made a virtual community a real community. It lifts everyone's boat.”
William Peck

Member since 2004