0

I have a TextBox named TextBoxValue and a Button named ButtonGetValue that are located on an ASP WebForm named DestinationPage.aspx. What I am doing is that I am filling the TextBox with a value that I am passing to this page from the previous page using a QueryString. I am implementing that in the following way:

<asp:Button ID="ButtonCompute" runat="server" Text="Compute" OnClick="ButtonCompute_Click" ValidationGroup="ComputeGroup"/

ButtonCompute is a Button located on SourcePage.aspx, and clicking it simply passed the data to DestinationPage.aspx from SourcePage.aspx. This is not the Button that I was talking about earlier.

Code in SoucePage.aspx.cs:

int valueForDestination = 10; 
Response.Redirect("~/DestinationPage.aspx?Value = + valueForDestination);

Code in DestinationPage.aspx.cs:

int valueFromQS = Request.QueryString["Value"];
TextBoxValue.Text = valueFromQS;

<asp:Button ID="ButtonGetValueValue" runat="server" Text="Get Value" onclick="ButtonGetValue_Click" /> 

Now, what I do here is, once the value is displayed in the TextBoxValue, change it to 100 from 10. And then I click on ButtonGetValue. But instead of getting 100; which is the updated value, I am getting 10; which was the initial value. How can I get the updated value?

EDIT 1.0 I apologize for not mentioning clearly what I want to do with ButtonGetValue. This Button simply reads the value from the TextBox and prints the value on the screen.

I am working on ASP.NET WebForms.

  • Are you setting `TextBoxValue.Text = valueFromQS` in an `IsPostBack` check? – VDWWD Dec 13 '17 at 15:47
  • No. It is inside `if (Request.QueryString.Count > 0)` and the `if condition` directly in `Page_Load()`. –  Dec 13 '17 at 15:51

1 Answers1

0

Unless you want it to change to the QueryString value on every postback, you want to wrap it in a !IsPostBack

if (!Page.IsPostBack)
{
    if (Request.QueryString["Value"] != null) 
    {
        TextBoxValue.Text = Request.QueryString["Value"].ToString();
    }
}

Also in your example code you are passing through 10 in the query string, and you are also saying the default value is 10, if you want it to be 100 then you need to pass 100 into the querystring on your button click event.

Arcane92
  • 57
  • 1
  • 10
  • Thank you for your answer. I have edited my question based on what you are asking. I apologize for not mentioning that piece of information while posting the question. I am performing the edit (10 -> 100) after I have got the query string. What I am trying to imply is that, even if I change the value to 100, on clicking `ButtonGetValue`, I am getting 10 as the output, whereas, I wanted 100 as I had changed `10` to `100` in the `TextBox`. Hope this helps. Also, I think your solution should work. I am testing that. –  Dec 13 '17 at 16:04