简体   繁体   中英

Problems with request.querystring

I have problems with the query strings. I have an aspx site with 3 comboboxes. When changing the value the querystring get's the selected value.

But when I change the values the url doesn't update immediatly:

For example:

Page name: test.aspx

Values combobox 1: Mo, Di, Mi
Values combobox 2: 1, 2, 3
Values combobox 3: A, B, C

Now when I change:

Combobox 1 -> Mo -> URL still test.aspx (but value of combobox is Mo!)
Combobox 2 (first ist still Mo) -> 1 -> Url gets test.aspx?Tag=Mo

It seems that the url updates with the previuos values but not with the actually ones.

I read the querystring on Page_LoadComplete

So is there a opinion to load the page with the actually querystrings? I would like to generate the page to pdf with wkhtmltopdf but when I take the input url Request.url the generated pdf is also not up to date...

thanks and sorry for my bad english

Update:

This is when I change the querystring.

protected void DD_Status_SelectedIndexChanged(object sender, EventArgs e)
    {
        PropertyInfo isreadonly = typeof(System.Collections.Specialized.NameValueCollection).GetProperty("IsReadOnly", BindingFlags.Instance | BindingFlags.NonPublic);
        isreadonly.SetValue(this.Request.QueryString, false, null);
        Request.QueryString["Status"] = this.DD_Status.SelectedValue.ToString();

This i when I read the querystring on Page_LoadComplete

 if (Request.QueryString["Status"] != null)
            DD_Status.SelectedValue = Request.QueryString["Status"];

Postback isn't used anywhere on the page

What is this line of code even trying to do?:

Request.QueryString["Status"] = this.DD_Status.SelectedValue.ToString();

By the time the request is received on the server, the URL has already been parsed. You can't change that URL on the server and expect it to be updated on the client somehow. To put it simply, Request.QueryString is for getting values from the URL that was posted to the server, not for saving values to the URL.

If you want to save a value in a location where a later page event can see it, just save it to a class-level variable. Something like this:

public class SomePage
{
    private string SelectedStatus { get; set; }

    protected void DD_Status_SelectedIndexChanged(object sender, EventArgs e)
    {
        SelectedStatus = this.DD_Status.SelectedValue.ToString();
    }

    protected void Page_LoadComplete(object sender, EventArgs e)
    {
        DD_Status.SelectedValue = SelectedStatus;
    }

    // other code in the code-behind class
}

Though, looking at this now, it's still not really clear what you're trying to do. Logically it looks like you're trying to set DD_Status.SelectedValue to, well, itself. You don't need to do that, it already has the value that it, well, has.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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