Server.Transfer的查询字符串 [英] server.Transfer with query string

查看:123
本文介绍了Server.Transfer的查询字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我初学者学习使用C#作为编程语言ASP.NET。

目前我与HTTPSERVERUTILITY工作。

我创建命名为Default.aspx的和Default2.aspx Web表单:

我写了下面的代码:

Default.aspx的:

在源代码视图


    
    

 < ASP:按钮的ID =Button1的=服务器的onclick =的button1_Click文本=按钮/>< / DIV>
< /表及GT;

在code隐藏文件:

保护无效的button1_Click(对象发件人,EventArgs的发送)
    {

  Server.Transfer的(Default2.aspx名= roseline&放大器;密码=传递@ 123);
}

编码为Default2.aspx:

在源视图:


    
    
        
        

        

        
        

        

    
        

    
    

在code隐藏文件:

 公共字符串N,P;
保护无效的Page_Load(对象发件人,EventArgs的发送)
{
    N =的Request.QueryString [名称];
    P =的Request.QueryString [密码];}
保护无效的button1_Click(对象发件人,EventArgs的发送)
{
    TextBox1.Text = N;
    TextBox2.Text = P;
}

当我执行上述应用程序,我没有得到任何错误。

当我点击Button1的Default.aspx中它让我看到Default2.aspx,但是当我点击我不是在TextBox得到的值按钮,文本框是空的,没有任何价值。

谁能告诉我什么是错我的编码?为什么它不是在文本框显示的数值?

请帮我出!

在此先感谢!


解决方案

您可以在不追加Server.Transfer的查询字符串。

您可以通过在上下文值

例如:

  Context.Items [PARAMNAME] =值;

您可以从这里 的Server.Transfer和Response.Redirect的之间的差异p>

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

这篇关于Server.Transfer的查询字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆