简体   繁体   English

request.querystring问题

[英]Problems with request.querystring

I have problems with the query strings. 查询字符串出现问题。 I have an aspx site with 3 comboboxes. 我有一个带3个组合框的aspx网站。 When changing the value the querystring get's the selected value. 更改值时,查询字符串将获得所选值。

But when I change the values the url doesn't update immediatly: 但是,当我更改值时,URL不会立即更新:

For example: 例如:

Page name: test.aspx 页面名称: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. 似乎url使用previuos值更新,而不是实际值。

I read the querystring on Page_LoadComplete 我在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... 我想使用wkhtmltopdf将页面生成为pdf,但是当我使用输入URL Request.url时,生成的pdf也不是最新的...

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 当我阅读Page_LoadComplete上的查询字符串时,这就是我

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

Postback isn't used anywhere on the page 页面上的任何地方都没有使用Postback

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. 到服务器上收到请求时,URL已被解析。 You can't change that URL on the server and expect it to be updated on the client somehow. 您无法在服务器上更改该URL,并希望以某种方式在客户端上对其进行更新。 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. 简单来说, Request.QueryString用于发布到服务器的URL中获取值,而不是用于将值保存 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. 从逻辑上来说,您似乎正在尝试将DD_Status.SelectedValue设置为本身。 You don't need to do that, it already has the value that it, well, has. 您不需要这样做,它已经具有它所具有的价值。

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

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