简体   繁体   English

ASP.NET中的Request.QueryString和OutputCache

[英]Request.QueryString and OutputCache in ASP.NET

I have a problem with Request.QueryString that returns a null value. 我在Request.QueryString上返回空值时遇到问题。 I think that is from OutputCache 我认为这是从OutputCache

I have in Default.aspx (with master file) 我在Default.aspx中(带有主文件)

<%@ OutputCache Duration="60" VaryByParam="button" %>

<script runat="server">
   protected void Page_Load( object sender, EventArgs e ) {
      TimeMsg.Text = DateTime.Now.ToString( "G" );
      string v = Request.QueryString["button"];
      PageName.Text = v;
   }
</script>

<form method="get" action="Default.aspx">
   <h5>Click a button</h5>
   <input type="submit" name="button" value="One" />
   <input type="submit" name="button" value="Two" />
   <input type="submit" name="button" value="Three" />
   </form>



   <p>Page generated at : <asp:Label ID="TimeMsg" runat="server"></asp:Label></p>
   <p>Page name : <asp:Label ID="PageName" runat="server"></asp:Label></p>

I don't write anymore the <asp:Content ID='' ...></asp> tag. 我不再写<asp:Content ID='' ...></asp>标记。

When I press one of button, the PageName returns empty that I checked the v variable with Debugger and I see that it returns null. 当我按下按钮之一时,PageName返回空,我用Debugger检查了v变量,然后看到它返回null。

Why ? 为什么呢

If you change Request.QueryString["button"]; 如果您更改Request.QueryString["button"]; to Request.Form["button"]; Request.Form["button"]; you will get the expected output. 您将获得预期的输出。 This is probably because of Form in your master page. 这可能是由于母版页中的Form

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM