Roll back dropdownlist after menuItem event
I have created a dropdownlist in my masterpage in which I can select a company. After a company is selected I get redirected, but what I'm looking for is a way to set this dropdownlist back to default value once another menu item is clicked from the navigation bar.
I created an event for the values of the menu. Here is the code i'm using:
protected void MenuAdmin_MenuItemClick(object sender, MenuEventArgs e)
{
if (e.Item.Value == "Something")
{
DropDownListComp.SelectedValue = "-1";
Response.Redirect("~/test/test.aspx");
}
}
My menu has a menuItem which has the value Something.
<asp:Menu ID="MenuAdmin" runat="server" CssClass="menu"
EnableViewSta开发者_如何学运维te="false" IncludeStyleBlock="false" Orientation="Horizontal"
Visible="false" Font-Names="Verdana" onmenuitemclick="MenuAdmin_MenuItemClick">
<Items>
<asp:MenuItem Text="Something" Value="Something"/>
</asp:MenuItem>
</Items>
</asp:Menu>
The dropdownlist I created which has the value -1 in a listitem looks like this:
<asp:DropDownList ID="DropDownListComp" runat="server"
onselectedindexchanged="DropDownListComp_SelectedIndexChanged"
DataSourceID="SqlDataSourceComp" DataTextField="tCompName"
DataValueField="tCompId" AutoPostBack="true" AppendDataBoundItems="True">
<asp:ListItem Text="--Select company--" Value ="-1" Selected="False"></asp:ListItem>
</asp:DropDownList>
So I'm wondering why this isn't working. The menu does redirect but it doesn't put my dropdownlist back to --Select company--. I tried figuring it out with a breakpoint and when it runs through the if statement and it says that the value is -1. It's like my main page isn't updated, just the main content. So I think I have to do a post back or something in the event? Thank you for the help.
I saw on other website the same problem. They solved it using a button next to the dropdownlist which gets the value of the selectedValue from the dropdownlist and redirects.
Actually the same event is fired as when you select anything in the dropdownlist at the first time.
Regards.
精彩评论