傳遞查詢字符串中的文本例如假設頁面的相對路徑是/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;
}
您也可以創建通過查詢字符串和默認文本給出的文本屬性。
這個技巧。謝謝 –