1.ASP.net后台cs代码中public string sql;或public string getsql()
则可以在前台通过中<% =sql%>或<% =getsql)%>获取到;
2.后台中可以通过LI1.Attributes["class"] = "active";
loginDiv.Attributes["style"] = "display:none";来为标签添加属性
3创建session和Cookies.
Session["phoneNum"] = tab.Rows[0]["phoneNum"].ToString();
Session["userName"] = tab.Rows[0]["userName"].ToString();
DateTime timeOut = DateTime.Now.Date.AddMinutes(30);
Response.Cookies["phoneNum"].Value = tab.Rows[0]["phoneNum"].ToString();
Response.Cookies["phoneNum"].Expires = timeOut;
Response.Cookies["userName"].Value = tab.Rows[0]["userName"].ToString();
Response.Cookies["userName"].Expires = timeOut;
获取if (Context.Session["phoneNum"] != null & Context.Session["userName"] != null)
4.获取当前网页url
【1】获取 完整url (协议名+域名+站点名+文件名+参数)
string url=Request.Url.ToString();
url= http://www.test.com/aaa/bbb.aspx?id=5&name=kelli
【2】获取 站点名+页面名+参数:
string url=Request.RawUrl;
(或 string url=Request.Url.PathAndQuery;)
url= /aaa/bbb.aspx?id=5&name=kelli
【3】获取 站点名+页面名:
string url=HttpContext.Current.Request.Url.AbsolutePath;
(或 string url= HttpContext.Current.Request.Path;)
url= aaa/bbb.aspx
【4】获取 域名:
string url=HttpContext.Current.Request.Url.Host;
url= www.test.com
【5】获取 参数:
string url= HttpContext.Current.Request.Url.Query;
url= ?id=5&name=kelli
6.前台获取select标签的选中值
<span class="select-box" style="width: 200px;" id="courseSpan">
<select class="select" size="1" name="selectcourse" id="selectcourse">
<option value="" selected>请选择报考课程</option>
<option value="英语+数学">英语+数学</option>
<option value="英语+政治">英语+政治</option>
<option value="单英语">单英语</option>
<option value="单数学">单数学</option>
<option value="单政治">单政治</option>
</select>
</span>
前台: var courseSpan = $("#courseSpan select option:checked").val();//所报课程
后台: string selectcourse = Request.Form["selectcourse"].ToString();//所报课程
<select name="subject" id="subject" runat="server">
<option value="英语">英语</option>
<option value="数学">数学</option>
<option value="政治">政治</option>
</select>
后台获取选定项的value:string subject=subject.Items[subject.SelectedIndex].Value;