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 aButton
located onSourcePage.aspx
, and clicking it simply passed the data toDestinationPage.aspx
fromSourcePage.aspx
. This is not theButton
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
.
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.