WebForm中 頁面傳參的總結

來源:互聯網
上載者:User

標籤:write   span   傳參   run   log   傳遞   back   http   接收   

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中的的值";
//讀取Applicationstring Application_str = Application["application"].ToString();Response.Write(Application_str);

 

WebForm中 頁面傳參的總結

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.