我该如何执行此任务 [英] How do I perform this task

查看:109
本文介绍了我该如何执行此任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。我有下面的代码



Hi all . I have the below code

public partial class Test : System.Web.UI.Page
{
    SqlConnection con = PublicClass.ConnectionString();
    protected void Page_Load(object sender, EventArgs e)
    {
        TextBox1.Text = Request.QueryString["Name"];
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Write("</br>");
        Response.Write("</br>");
        Response.Write(TextBox1.Text);
    }
}





http:// localhost:18128 / test.aspx?name = aaa



在我的文本框aaa中出现,我想写一些例如bbb在我的文本框中,只要按下按钮bbb就出现在屏幕上,这部分



as soon as i open my URL : http://localhost:18128/test.aspx?name=aaa

in my Text box aaa appear and i would like to write for example bbb in my textbox and as soon as press on button bbb appear on screen whit this part

Response.Write(TextBox1.Text);





但无论我写什么,只有aaa出现在screan上。请帮助我:)



but whatever i write only aaa appear on screan . please help me :)

推荐答案

如果你想在文本框中出现bbb,你需要将它作为查询字符串发送

http:// localhost:18128 / test.aspx?name = bbb [ ^ ]

然后只将文本框文本设置为bbb和响应单击按钮时文本为bbb。

如果您请求 http:/ /localhost:18128/test.aspx?name=aaa [ ^ ]然后您在文本框中键入bbb并单击按钮将不会更改页面的查询字符串,它将再次将查询字符串中的前一个aaa加载回文本框。希望这能帮助你理解正在发生的事情。



编辑:

在页面加载中添加IsPostBack验证如下

if you want to appear "bbb" on textbox you need to send it as query string
http://localhost:18128/test.aspx?name=bbb[^]
then only it will set textbox text as "bbb" and response text as "bbb" when you click on the button.
if you request page with http://localhost:18128/test.aspx?name=aaa[^] then later you type "bbb" in textbox and click on button will not change the query string of the page, again it will load previous "aaa" from the query string back to textbox. hope this will help you to understand what is happening.


add IsPostBack validation in page load as below
protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        TextBox1.Text = Request.QueryString["Name"];
    }
}


这篇关于我该如何执行此任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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