QueryString problem in .aspx - not outputting anything

I need to print the querystring value "? Type = xxx" inside my .aspx page, why doesn't this work:

<%= Request.QueryString("type") %>

      

While this does:

<%= Request.QueryString(0) %>

      

The first does not output anything, the second prints the value as expected, but that is not always the first value I want ...

Any ideas?

I redirect to "modrewrite.aspx" for 404 errors in the Custom Errors tab in IIS and then pick up the correct page based on what was asked for. However, it is strange that it works with an indexed and unnamed value ...

I managed to find a strange solution; If I put a dummy value first, then I can select the value as expected.

This works: "? Dummy = value & type = xxx" Now I can collect the value with <% = Request.QueryString ("type")%>

+2


a source to share


4 answers


It's just a cheap shot.

Try

<%= Request.QueryString["type"] %>

      



or

<%= Request.QueryString('type') %>

      

0


a source


I would parse the value in my code, perform any security checks on it to check for QueryString manipulation, and then set it to the Text property of the Literal control on the page.



lit1.Text = Request.QueryString["type"];

      

0


a source


In your aspx place a shortcut:

<asp:Label ID="typeLabel" runat="server" />

      

and in your code assign a value to it:

protected void Page_Load(object sender, EventArgs e)
{
    typeLabel.Text = Request["type"];
}

      

Adapt the code to VB.NET if necessary

0


a source


I managed to figure it out: If I put a dummy value first, then I can select the value as expected.

It works: "?dummy=value&type=xxx"

Now I can collect the value with <%= Request.QueryString("type") %>

Interesting.

0


a source







All Articles