0

i have a textbox control in asp.net. textbox have a search button beside it. On clicking the search button i redirect to new page with the value in textbox. the new page also hase textbox and button beside it. I set the value sent from previous page to the textbox on new page. If i change the value on new page and click the search button it should take the new value. But it takes the previous value. on page load method wrote the following code.

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        str1 = Request.QueryString("str1").ToString()
        flag = Request.QueryString("flg")
        txtsrch.Text = str1
End Sub

On button click following code

Protected Sub bsrcnew_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles bsrcnew.Click
        Dim s As String


        s = txtsrch.Text

        If (flag.Equals(0)) Then
            Response.Redirect("newSearch.aspx?str1=" + s)
        ElseIf (flag.Equals(1)) Then
            Response.Redirect("termsnew.aspx?str1=" + s)

        End If
end sub

can any1 tell me how do i get changed value in textbox?

2 Answers 2

1

Try assigning it in a

If(!IsPostBack)
    {
            str1 = Request.QueryString("str1").ToString()
            flag = Request.QueryString("flg")
            txtsrch.Text = str1
    }

On buttonclick its again assigning the value from query string.

Sign up to request clarification or add additional context in comments.

Comments

1

Use IsPostBack to set your text box only on the first run in the second page. Example:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  If Not IsPostBack
    str1 = Request.QueryString("str1").ToString()
    flag = Request.QueryString("flg")
    txtsrch.Text = str1
  End If
End Sub

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.