1.Form表单传递(get/post)
前台:
1 姓名:<input id="TxtValue" name="TxtName" type="text" /><br /> 2 年龄:<input id="AgeValue" name="AgeValue" type="text" /><br /> 3 性别:<input type="radio" name="sex" value="男" />男 4 <input type="radio" name="sex" value="女" />女 5 爱好:<select id="SltLike" name="SltLike"> 6 <option value="like1">打球</option> 7 <option value="like2">睡觉</option> 8 <option value="like3">上网</option> 9 </select><br /> 10 <input type="submit" value="提交" />
后台使用一般处理程序接收:
string Name = context.Request["TxtName"].ToString(); string Age = context.Request["AgeValue"].ToString(); string Sex = context.Request["sex"].ToString(); string Like = context.Request["SltLike"].ToString();
2.使用URL传值
前台:
<%---------- URL 传参----------------%> <a href="WebForm1.aspx?Value1=123&Value2=txt">URL传参</a><br /> <asp:Button ID="Button1" PostBackUrl="WebForm1.aspx?Userid=1" runat="server" Text="Post页面传值" Height="27px" OnClick="Button1_Click" /><br />
后台:
string Value1 = Request.QueryString["Value1"]; string Value2 = Request.QueryString["Value2"];
3.Session传值
前台:
1 <%---------- Session 传参----------------%> 2 <asp:Button ID="Button2" runat="server" Text="读取Session" OnClick="Button2_Click" /><br />
后台:
//写入Session Session["SessionValue"] = "我是Session中的值";
//读取 string Session_Str = Session["SessionValue"].ToString(); Response.Write(Session_Str);
4.Cookie传值
前台:
<%---------- Cookie 传参----------------%> <asp:Button ID="Button3" runat="server" Text="读取Cookies" OnClick="Button3_Click" /><br />
后台:
//写入cookie HttpCookie cook = new HttpCookie("Cook", "我是Cookie中的值"); Response.Cookies.Add(cook);
//读取Cookie HttpCookie cook = Request.Cookies["Cook"]; Response.Write(cook.Value);
5.Application传值
前台:
<%---------- Application 传参----------------%> <asp:Button ID="Button4" runat="server" Text="读取Application" OnClick="Button4_Click" /><br />
后台:
//写入Application Application["application"] = "我是Application中的的值";
//读取Application string Application_str = Application["application"].ToString(); Response.Write(Application_str);
时间: 2024-12-28 15:49:13