通过查询字符串中的文本,例如,假设页面的相对路径是 / pagename.aspx,您可以按下面的示例通过查询字符串:
/pagename.aspx?text=hello
在 page_Load 事件中, c# 写入以下代码
//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;
}
也可以为通过查询字符串和默认文本提供的文本创建属性。