Results 1 to 8 of 8

Thread: Update is not picking up current value of text box

Threaded View

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2006
    Posts
    589

    Update is not picking up current value of text box

    Here is an extract of some code on a webform. The code is within a GridView called gvContactSummary.

    Code:
    <asp:TemplateField HeaderText="Details">
        <ItemTemplate>
            <asp:HyperLink ID="hlDetails" runat="server"></asp:HyperLink>
            <asp:Label runat="server" ID="lblDescription" Text="" ToolTip='<%# Eval("Description")%>' />
        </ItemTemplate>
        <EditItemTemplate>
            <asp:TextBox runat="server" ID="txtValue" Text='<%# Eval("Details")%>' CssClass="NormalTextbox"
                Width="320px" />
        </EditItemTemplate>
    </asp:TemplateField>
    when you click the edit link that appears a bit further across the grid the 'EditItemTemplate' is displayed and the Textbox with ID="txtValue" appears - with the correct data to edit displayed in it.

    If I change the data in the text box and click Update this happens ... (just an extract)

    Code:
                DataAccess da = new DataAccess();
                GridViewRow row = gvContactSummary.Rows[e.RowIndex];
                Label AIID = (Label)row.FindControl("AIID");
                Label LocationID = (Label)row.FindControl("LocationID");
                Label Type = (Label)row.FindControl("lblType");
                TextBox txtVal = (TextBox)row.FindControl("txtValue");
    
                if (AIID.Text != "0")
                {
                    //Update Addn info ID
                    string Description = "";
                    da.UpdateContactAddnContactInfo(Convert.ToInt32(AIID.Text), txtVal.Text, Description);
                }
    Now I know the update is happening correctly because if I hard code the value of the text box 'txtValue' this hard-coded value is then written to the database when Update is clicked.

    But, when it is not hardcoded - ie. when the textbox contains a value from the database (in this case a phone number) then ...

    If I click Edit- the textbox appears and I remove the existing phone number, enter a new one and click Update. But the value of txtVal.Text is showing the number before I edited it.

    Can anyone explain why, when the Update link is clicked, txtVal.Text does not contain the current value of the text box txtValue - it contains the original value.

    Thanks for any help. Spent all afternoon on this and got nowhere!
    Last edited by Webskater; Sep 4th, 2007 at 11:36 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width