I am beginner learning ASP.NET with C# as the programming language.
Currently I am working with HTTPSERVERUTILITY.
I have created a web form named as Default.aspx and Default2.aspx:
I have written the following coding :
Default.aspx:
In source view
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
</div>
</form>
In Code-behind file:
protected void Button1_Click(object sender, EventArgs e) {
Server.Transfer("Default2.aspx ? name =roseline & password = pass@123");
}
Coding for Default2.aspx:
In Source View:
In Code-Behind File:
public string n, p;
protected void Page_Load(object sender, EventArgs e)
{
n = Request.QueryString["name"];
p = Request.QueryString["password"];
}
protected void Button1_Click(object sender, EventArgs e)
{
TextBox1.Text = n;
TextBox2.Text = p;
}
When I execute the above application I am not getting any error.
When I click on the Button1 in Default.aspx it shows me the Default2.aspx, but when I click on the button I am not getting the values in the TextBox, the TextBoxes are empty without any values.
Can anyone tell me what is wrong with my coding? Why it is not displaying the values in the TextBoxes?
Please help me out!
Thanks in advance!
You can't append a query string in Server.Transfer.
You can pass values in Context
Eg:
Context.Items["ParamName"] = value;
You can get the differences between Server.Transfer and Response.Redirect from here
You can use this way.
string url = $"~/Registration.aspx?price={price}&membershipId={membershipId}";
Server.Transfer(url);
And to read the values simply you need to use:
string membershipId = Request.QueryString["membershipId"];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With