box1763 box1763 - 6 months ago 18
Vb.net Question

vb.net TextBox submit not changing

I've got a legacy VB.Net app that I'm modifying in VS 2010; here's the relevant code:



<form id="form1" runat="server">
<asp:GridView ID="gvCommentsEdit" runat="server" ShowHeader="False">
<Columns>
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
*** On
<asp:Label ID="lblTimestamp" runat="server" Text='<%# Bind("comment_date") %>'></asp:Label>
<asp:Label ID="lblUpdateBy" runat="server" Text='<%# Bind("update_by") %>'></asp:Label> commented:<br />
<asp:TextBox ID="txtEditCommentPopup" runat="server" Columns="55" Rows="10" Text='<%# bind("text") %>' TextMode="MultiLine"></asp:TextBox>
<asp:LinkButton ID="lnkSaveComment" runat="server" OnClick="lnkSaveComment_Click">Save</asp:LinkButton>
<asp:LinkButton ID="lnkCancelEdit" runat="server" OnClick="lnkCancelEdit_Click">Cancel</asp:LinkButton>
<asp:HiddenField ID="hdnCommentID" Value='<%# Bind("comment_id") %>' runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</form>


Code Behind is:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

Dim IdNumber As Integer = sender.ClientQueryString
Dim mydata As New Profile_Data

gvCommentsEdit.DataSource = mydata.returnCommentsById(RequestedUsername, IdNumber)
gvCommentsEdit.DataBind()

End Sub

Sub lnkSaveComment_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim myRow = sender.parent
Dim mydata As New Profile_Data
Dim IdNumber As String = CType(myRow.FindControl("hdnCommentID"), HiddenField).Value
Dim text As String = CType(myRow.FindControl("txtEditCommentPopup"), TextBox).Text

mydata.UpdateComment(IdNumber, text)

Page.ClientScript.RegisterClientScriptBlock(Me.GetType(), "CloseWindowScript", "window.opener.location.href = window.opener.location;window.close();", True)
End Sub


End Class

This page is a popup from the main page and populates fine. The problem is when I change the txtEditCommentPopup TextBox, which then calls lnkSaveComment_Click(), it has the original textbox values, not the changed value. I'm not using AutoPostBack. Any ideas on why? Thanks!

Answer

I added this in your page load

If Not IsPostBack Then 
     'your code 
  End If

so replace your Page_Load with this:-

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load    
    If Not IsPostBack Then

       Dim IdNumber As Integer = sender.ClientQueryString
       Dim mydata As New Profile_Data

       gvCommentsEdit.DataSource = mydata.returnCommentsById(RequestedUsername, IdNumber)
       gvCommentsEdit.DataBind()
  End If   
End Sub

Hope this will help you.

Comments