Asp.Net第四章(跨页面传值)

使用Response.Write向页面输出信息

1、向页面输出html文本格式字符串
Response.Write("111");

Response.Write("<b>111<b>");

2、弹出提示信息
Response.Write("<script>alert('1111')</script>");

总结说明:Response.Write(数据)用于向前台输出信息,支持html标签,还可以执行js脚本

注意事项:修改后台代码需要重新生成项目之后才能看到效果!

1、Response对象
此对象有三个方法
①Write 写入
②End 终止
③Redirect 转向另一页面


2、跨页面传值(3种)


    1、在原页面中跳转
    protected void Button1_Click(object sender, EventArgs e)
    {   
        Response.Redirect(TextBox1.Text);
        //跳转到从TextBox1中输入的页面
        //如:在TextBox1中输入 http:/www.baidu.com
        //则跳转到http:/www.baidu.com
    }

 

    2、另外打开一个新页面   
    protected void Button1_Click(object sender, EventArgs e)
    {   
        Response.Write("<script>open('"+TextBox1.Text+"','_blank')</script>");
    }
    
    注:在新页面里显示TextBox1输入的文本信息 并在Button里加        PostBackUrl="~/WebForm1.aspx"
    在form里加method="post"
        protected void Page_Load(object sender, EventArgs e)
        {

            Response.Write(Request.Form["TextBox1"]);
        }
    注:
    <asp:Button ID="Button1" runat="server" Text="Button" PostBackUrl="~/WebForm1.aspx" />
    <form id="form1" runat="server" method="post">

 


    3、打开另一页面,并把文本框的内容显示出来
        protected void Button1_Click(object sender, EventArgs e)
        {   
            //Response.Redirect("WebForm1.aspx?name=" + TextBox1.Text + "&pwd" + TextBox2.Text);
        }
    
    注:WebForm1.aspx?里的load
    protected void Page_Load(object sender, EventArgs e)
        {
            string name = Request.QueryString["name"];
            string pwd = Request.QueryString["pwd"];
            Response.Write("姓名:" + name);
            
        }

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值