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!

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.