传递查询字符串中的文本,例如假设页面的相对路径是 /pagename.aspx ,您可以按照下面给出的示例传递查询字符串:
/pagename.aspx?text=hello
在 c# 中在 Page_Load 事件中编写以下代码
//You don't have to check the url all the time , so just check it if page is not posting back (first time after user visits the page and ignore all other same page post backs. Label can maintain its control state (text value) after every postback, so assign it only once to increase performance
if (!IsPostBack)
{
//Check if query string is provided or not , if it is not provided take some default text, I am taking empty string as default text.
string givenText = (Request.QueryString["text"] == null)?"":Request.QueryString["text"];
label1.Text = givenText;
}
您还可以为通过查询字符串和默认文本给出的文本创建属性。