开发者

keep the selected item of dropdown list when the page is being reloaded

i have asp.net DropDownList and Button. Once i click on the button it will set some value of java script variable. when i select the item from drop down list according to that previous set java script variable, 开发者_运维问答query string should be updated.

i have done query string updated.but the problem is drop down selected item will change to the default item due to the post back.

Note: i need to do window.location.href = newQStr; inorder to affect the updated query string.

what i want is keep the selected item of drop down list without changing due to the post back.

i'm using jquery for clint side operations.

any idea..?

Thank in advance


The way you're doing it, the page does not do a postback in the traditional sense. You're just redirecting back to the same url with an updated QueryString parameter. I'm not sure if there's a reason why you're doing it that way, but why not add an event handler for the button to set the selected value of the select? Here's an example:

<asp:Button ID="Button1" runat="server" Text="Hello" OnClick="Button1_Click" ... />

And in the code behind:

protected void Button1_Click(object sender, EventArgs e)
{
    //do some logic to figure out what the selected value should be

    ListItem item = DropDownList1.Items.FindByValue("SomeValue");
    if (item != null)
        item.Selected = true;
}


why do you dont work with page_load is postback and select again the item? I think is a cycle problem, not a code problem. Maybe you may think again the logic.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜