Hi all,

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

<body>
    <form id="form1" runat="server">
    <div>
    
        <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
    
    </div>
    </form>
</body>

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:

<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="TextBox1" runat="server" Text ="A"></asp:TextBox>
        <br />
        <br />
        <asp:TextBox ID="TextBox2" runat="server" Text = "B"></asp:TextBox>
        <br />
        <br />
    <asp:Button ID = "Button1" runat ="server" Text = "Button1"  onclick="Button1_Click" />
        <br />
    </div>
    </form>
</body>

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.


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!

Dani AI

Generated

Short summary and practical fixes. The immediate cause was a malformed URL: spaces around ?, = and & make the query string invalid so Request.QueryString[...] returns null (as pointed out). Both server-side transfer and client redirect will carry a well-formed query string (as verified), but putting a password into a query string is unsafe and should be avoided.

Server.Transfer vs Response.Redirect (clarification)

  • Server.Transfer hands execution to another ASPX on the server; the browser URL stays the same. This is fine for same‑site internal navigation and avoids an extra round trip.
  • Response.Redirect sends a 302 to the browser, which performs a new request and updates the URL. Use Redirect when the browser must show the new address or when navigating to another domain.
  • Both are standard and supported by browsers; IE “problems” are usually due to caching, security settings, or malformed URLs rather than ASP.NET itself (addressing ’s comment).

Safer ways to pass data (preferred)

  • For single, server-only transfers, use Context.Items to pass values without exposing them in the URL:
// sender page (Default.aspx.cs)
Context.Items["name"] = "roseline";
Context.Items["password"] = "pass@123";
Server.Transfer("Default2.aspx");
// target page (Default2.aspx.cs)
protected void Page_Load(object sender, EventArgs e)
{
    if (Context.Items["name"] != null)
    {
        TextBox1.Text = (string)Context.Items["name"];
        TextBox2.Text = (string)Context.Items["password"];
    }
}
  • For longer-lived data across requests, use Session (do not store plain passwords), or submit via POST and use Server.Transfer(path, true) to preserve form data.
  • Always use HTTPS for any sensitive data and never expose credentials in query strings or browser history.

Troubleshooting checklist

  • Remove spaces in the URL string and test again.
  • Verify event handlers are wired correctly and inspect Request.QueryString in the debugger.
  • If links break after Transfer, remember the browser still shows the original URL (affects relative paths).

Recommended Answers

All 5 Replies

You need using static properties to pack the parameter values, and,
use Response.Redirect(URL) instead of Server.Transfer(URL).

Everything will be fin. Note that the modified code will work on firefox but not on IE.

Your code on Default.aspx is as shown below

Server.Transfer("Default2.aspx ? name =roseline & password = pass@123");

change the above code by avoiding space in the string
Shown below

Server.Transfer("Default2.aspx?name=roseline&password=pass@123");

There is not any mistake, it should have work, please try, might be there is mistake in assignment

I have just run your code using Server.Transfer and Response.Redirect both worked well. The only thing you need to do is to write your url without space as follows:

Server.Transfer("Default2.aspx?name=roseline&password=pass@123");

or

Response.Redirect("Default2.aspx?name=roseline&password=pass@123");

If this is helpful please mark this post as solved.

Have you ever tried forward outbound domain. this should give you an interesting example of why we need using Redirect, and in addition, why IE is not helpful in some cases.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.