我有一個會話變量把一個會話變量到一個文本框
Session["customerID"]
我希望把這個文本框裏面。我將如何做到這一點?
我已經試過
TextBox1.Text = Session ["customerID"]
我有一個會話變量把一個會話變量到一個文本框
Session["customerID"]
我希望把這個文本框裏面。我將如何做到這一點?
我已經試過
TextBox1.Text = Session ["customerID"]
if(Session["customerID"] != null)
{
TextBox1.Text = Session["customerID"].ToString();
}
我想補充一個空的檢查,以確保您的代碼如果會話變量未定義,則不會失敗
TextBox1.Text = Session ["customerID"].ToString();
投Session對象爲String並將其分配給文本框:
TextBox1.Text = Session ["customerID"].ToString();
你可以簡單地引用它,就像你將一個值存儲到它一樣。
if(Session["customerID"] != null)
{
TextBox1.Text = Session["customerID"];
}
這也可以作爲一個簡單的襯墊使用三元完成運算符(?):
要經常檢查一個特定的密鑰已經在會話中同樣存在是很重要的
TextBox1.Text = Session["customerID"] ?? "";
請使用 的document.getElementById( 「<%= txtName2.ClientID%>」)值= '<%=會話[ 「DmName」]的ToString()%>';
是這個asp.net? – 2013-05-13 18:51:23
是的,它是asp.net – joshuahornby10 2013-05-13 18:51:49
你是如何設置變量值的? 「放置在文本框中」聽起來很奇怪......你想做什麼? – gustavodidomenico 2013-05-13 18:52:55