简体   繁体   中英

modal pop-up ok button not working as expected for a dropdown menu

CODE BEHIND:

  private void Page_Load(object sender, System.EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            ddlLanguage.SelectedValue = Thread.CurrentThread.CurrentCulture.Name;
        }

    }



    protected void ddlLanguage_SelectedIndexChanged(object sender, EventArgs e)
    {

        if (ddlLanguage.SelectedValue == "es-ES")
        {
            mdlPopup.Show();
        }
        //Sets the cookie that is to be used by Global.asax
        HttpCookie cookie = new HttpCookie("CultureInfo");
        cookie.Value = ddlLanguage.SelectedValue;
        Response.Cookies.Add(cookie);

        //Set the culture and reload the page for immediate effect. 
        //Future effects are handled by Global.asax
        Thread.CurrentThread.CurrentCulture = new CultureInfo(ddlLanguage.SelectedValue);
        Thread.CurrentThread.CurrentUICulture = new CultureInfo(ddlLanguage.SelectedValue);
        //Server.Transfer(Request.Path);
    }


    protected void OKButton_Click(object sender, EventArgs e)
    {
        Server.Transfer(Request.Path);
    }

ASPX PAGE:

 <asp:DropDownList ID="ddlLanguage" class="langpnl" runat="server" AutoPostBack="True"
      OnSelectedIndexChanged="ddlLanguage_SelectedIndexChanged">
   <asp:ListItem Value="en-US">Eng</asp:ListItem>
   <asp:ListItem Value="es-ES">Esp</asp:ListItem>
 </asp:DropDownList>
<ajaxToolkit:ModalPopupExtender ID="mdlPopup" runat="server" TargetControlID="testhidden"
   PopupControlID="pnlPopup" OkControlID="OKButton" />
<asp:Panel ID="pnlPopup" runat="server" Width="500px" Style="display: none">
   All content may not be in Spanish.
<asp:Button ID="OKButton" runat="server" Text="OK" OnClick="OKButton_Click" />
</asp:Panel>
<asp:HiddenField ID="testhidden" runat="server" />

I am trying to set the language as per the selection in the Dropdown box. But if the user selects spanish I want to display a popup modal with a msg & once the button OK is pressed I want to postback the whole page. Currently I am able to display the popup but the page never refreshed so the language still doesn't change. In the code behind if I remove the server.transfer from the OK button and put it in the SelectIndexChange then the page postback is working but there is no popup masg .I think the page gets postback after the popup executes so it never gets displayed...please need some help I am breaking my head since last 3 days.

Define another button in that panel... and do whatever you want in his onclick event. So you will have a postback.

The OKButton click event... OKButton_Click will not fire as long as you assigned him in you modalpopup...

 if (ddlLanguage.SelectedValue == "es-ES")
        {
            mdlPopup.Show();
        }
  else
        {
            Server.Transfer(Request.Path); 
        }

& removed the OK button from Modalpopup..finally got to see what I was Expecting..

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