QueryString
¡¡¡¡QueryString¶ÔÏóÖб£´æµÄÊý¾ÝÓɵ¥¶ÀµÄÓû§Ê¹Óá£ËüµÄÉúÃüÖÜÆÚ¿ÉÄÜÖ»ÓÐÒ»¸öÇëÇóÄÇô¶Ì£¬Ò²¿ÉÄÜÓÐÓû§Ê¹ÓÃÓ¦ÓóÌÐòµÄʱ¼äÄÇô³¤£¨Èç¹û¹¹ÔìÕýÈ·µÄ»°£©¡£ÕâÀàÊý¾ÝÒ»°ãСÓÚ1KB¡£QueryStringÖеÄÊý¾ÝÔÚURLÖд«µÝ£¬¶ÔÓÚÓû§À´ËµÊǿɼûµÄ£¬Òò´ËÄãÄܲµ½£¬Ê¹ÓÃÕâÖÖ¼¼Êõʱ£¬Ãô¸ÐµÄÊý¾Ý»ò¿ÉÓÃÓÚ¿ØÖÆÓ¦ÓóÌÐòµÄÊý¾ÝÐèÒª¼ÓÃÜ¡£
¡¡¡¡Ò²¾ÍÊÇ˵£¬QueryStringÊÇÔÚASP.NET Web´°Ìå¼ä·¢ËÍÐÅÏ¢µÄÒ»ÌõºÜºÃµÄ;¾¶¡£ÀýÈ磬Èç¹ûÓÐÒ»¸öº¬ÓвúÆ·ÁбíµÄÊý¾Ý±í¸ñ£¨DataGrid£©£¬²¢ÇÒÔÚ±í¸ñÉÏÓÐÒ»¸öÁ´½Óµ¼Ïò²úÆ·µÄϸ½ÚÒ³Ã棬ʹÓÃQueryString¾ÍÊÇÀíÏëµÄ£¬¿ÉÒ԰ѲúÆ·µÄID°üº¬ÔÚÁ´½Óµ½²úƷϸ½ÚÒ³ÃæµÄQueryStringÖУ¨ÀýÈçproductdetails.aspx?id=4£©¡£Ê¹ÓÃQueryStringsµÄÁíÒ»¸öºÃ´¦ÊÇÒ³ÃæµÄ״̬°üº¬ÔÚURLÖС£ÕâÒâζ×ÅÓû§¿ÉÒÔ°Ñij¸öͨ¹ýQueryStrings½¨Á¢µÄ´°Ìå·ÅÈëËûµÄÊղؼÐÖС£µ±ËüÃÇ×÷ΪÊղطµ»Øµ½Ò³Ãæʱ£¬½«Óë×÷ÊղصÄʱºòÒ»Ñù¡£ºÜÃ÷ÏÔÕâÖ»ÔÚÒ³Ãæ²»ÒÀÀµQueryStringÍâµÄËùÓÐ״̬ºÍ²»×÷ÈκθıäµÄʱºòÓÐ×÷Óá£
¡¡¡¡Ãô¸ÐÊý¾Ý£¬ÒÔ¼°Èκβ»Ï£ÍûÓû§²Ù×÷µÄ±äÁ¿Ó¦¸Ã±ÜÃâ³öÏÖÔÚ´Ë´¦£¨³ý·Ç¼ÓÃÜʹÓû§²»ÄÜÔĶÁ£©¡£²¢ÇÒURLÖв»ºÏ·¨µÄ×Ö·û±ØÐëʹÓÃServer.UrlEncode±àÂ룬Èçͼ7Ëùʾ¡£µ±´¦Àíµ¥¸öASP.NETÒ³Ãæʱ£¬¶Ôά»¤×´Ì¬À´ËµViewStateÊDZÈQueryStringºÃµÄÑ¡Ôñ¡£¶ÔÓÚ³¤ÆÚµÄÊý¾Ý´æ´¢£¬Cookie¡¢Sessions»òCache¶¼±ÈQueryStrings¸ü¼ÓÊÊÓÚ×÷ΪÊý¾ÝÈÝÆ÷¡£
¡¡¡¡Querystring.aspx
£¼form id="Querystring" method="post" runat="server"£¾ £¼asp:validationsummary id="valSummary" Runat="server"£¾ £¼/asp:validationsummary£¾ £¼table£¾ £¼tr£¾ £¼td colSpan="3"£¾Set Querystring Variable:£¼/td£¾ £¼/tr£¾ £¼tr£¾ £¼td£¾Name£¼/td£¾ £¼td£¾£¼asp:textbox id="txtName" Runat="server"£¾£¼/asp:textbox£¾ £¼/td£¾ £¼td£¾£¼asp:requiredfieldvalidator id="nameRequired" runat="server" Display="Dynamic" ErrorMessage="Name is required." ControlToValidate="txtName"£¾* £¼/asp:requiredfieldvalidator£¾£¼/td£¾ £¼/tr£¾ £¼tr£¾ £¼td£¾Value£¼/td£¾ £¼td£¾£¼asp:textbox id="txtValue" Runat="server"£¾ £¼/asp:textbox£¾£¼/td£¾ £¼td£¾£¼asp:requiredfieldvalidator id="valueRequired" Runat="server" Display="Dynamic" ErrorMessage="Value is required." ControlToValidate="txtValue"£¾* £¼/asp:requiredfieldvalidator£¾£¼/td£¾ £¼/tr£¾ £¼tr£¾ £¼td colSpan="3"£¾£¼asp:button id="btnSubmit" Runat="server" Text="Update Value"£¾£¼/asp:button£¾£¼/td£¾ £¼/tr£¾ £¼/table£¾ £¼asp:Label ID="lblResult" Runat="server" /£¾ £¼a href="querystring.aspx?x=1"£¾Set querystring x equal to 1£¼/a£¾ £¼/form£¾ Querystring.aspx.cs private void Page_Load(object sender, System.EventArgs e) { // ¼ìË÷cookieµÄÖµ if(Request.QueryString.HasKeys()) { lblResult.Text = "The values of the £¼b£¾" + txtName.Text + "£¼/b£¾ querystring parameter are:£¼br£¾"; foreach(string key in Request.QueryString.Keys) { lblResult.Text += "[" + key + " = " + Request.QueryString[key].ToString() + "]£¼br£¾"; } } }
private void btnSubmit_Click(object sender, System.EventArgs e) { if(IsValid) { string url = "querystring.aspx?"; foreach(string key in Request.QueryString.Keys) { url += key + "=" + Request.QueryString[key].ToString() + "&"; } Response.Redirect(url + txtName.Text + "=" + Server.UrlEncode(txtValue.Text)); } } |
´úÂë¶Î4.ÔÚASP.NETÖÐʹÓÃQueryStrings´«µÝÊý¾Ý