查询字符串保持不变. [英] Query String remains the same.

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

问题描述

我是aspx的新手,并且有这样的情况:

用户将在文本框中键入内容,当他单击按钮时,页面将使用他在文本框中键入的查询字符串重定向到自身.

这是我的代码:

I am new to aspx and have such a scenario:

User will type in a textbox and when he clicks a button the page will be redirected to itself with the query string he typed into textbox.

Here is my code:

Response.Redirect("somepage.aspx?parameter=" + txtbox1.text,false);<br />



并在页面加载期间:



and during page load:

txtbox1.text = Request.QueryString["parameter"]<br />



它仅在第一次成功运行.用户在文本框中键入其他内容并单击按钮后,查询字符串保持不变.我在做什么错?



It works succesful only for the first time. After user types something else into the textbox and clicks the button the querystring remains the same. What am I doing wrong?

推荐答案

我不明白这里的目的.您无需使用查询字符串即可将数据回传到同一页面.查看ViewState或其他形式的持久性.
I don''t understand the purpose here. You don''t need to use a query string to postback data to the same page. Look at ViewState or other forms of persistance.


正如Mark所说,在将查询字符串回发给自己时,不需要使用Query字符串.要添加更多内容,查询字符串是维护状态并将信息传递到另一页的一种方法.
在您的情况下,如果您回发到同一页面,则可以在后面的代码中直接访问所有值.无需使用/提供查询字符串.那不是uery字符串的方式/使用.
As Mark, said, you don''t need to use Query string while posting it back to itself. To add more, Query string is one of the way to maintain state and pass on information to another page.
In your case, if you postback to the same page, all the values are directly accessible to you in code behind. No need to use/give query string. Thats not the way/use of uery strings.


尝试添加:

如果(!Page.IsPostBack)txtbox1.text = Request.QueryString ["parameter"]

没有它,文本框将始终将其值设置为querystring值.

伙计们,这样做并不像乍看起来那样愚蠢……例如,谷歌将在其搜索结果页面上执行此操作,以使用当前搜索词预填充搜索文本框.
Try adding:

if (!Page.IsPostBack) txtbox1.text = Request.QueryString["parameter"]

Without it the text box will always have it''s value set to the querystring value.

Guys, doing this isn''t as daft as it may seem on first glance...for example Google will do this on their search results page to prepopulate the search text box with the current search terms.


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

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