Click here to Skip to main content
15,896,453 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Experts,

Below is my Drop down. On selected index changed I have one more drop down that gets bound.

XML
<asp:DropDownList ID="ddlManufacturer" AutoPostBack="true" Width="100%"
                 runat="server" DataTextField="I001001" DataValueField="I001001"
                 OnSelectedIndexChanged="ddlManufacturer_SelectedIndex" Height="16px" >
             </asp:DropDownList>


During this time, I want to call a JavaScript pleasewait() Till Second drop down binds.

I tried doing Google and I did my try as well and It worked weird. It shows pleasewait() but not till the second drop down binds. It shows and vanishes and then second drop down fills. But I want to show till the second dropdown is bind
Can anyone help me with this please?
Posted
Comments
F-ES Sitecore 17-Mar-15 16:19pm    
The page is doing a refresh when you change the drop down so any message etc you show is instantly destroyed and the browser waits for the new page to download and render. To do this with any great effect you'd need to wrap the relevant controls in an UpdatePanel so that the page doesn't refresh, but the controls are re-populated via ajax instead. That will give you a chance of showing a "please wait" message that remains until the update is done.
sudevsu 17-Mar-15 16:55pm    
My drop downs are in update panel already

XML
<script type="text/javascript">
    // note order is important, this has to go at the top
    function showMessage() {
        $("#pleaseWait").show();
    }

    function hideMessage() {
        $("#pleaseWait").hide();
    }
</script>

<form id="form1" runat="server">

<div id="pleaseWait">Please wait...</div>

<asp:ScriptManager runat="server" />

<asp:UpdatePanel runat="server">
<ContentTemplate>
    <asp:DropDownList ID="ddlParent" runat="server" AutoPostBack="true" onchange="showMessage()"
        OnSelectedIndexChanged="ddlParent_SelectedIndexChanged">
        <asp:ListItem runat="server">Parent A</asp:ListItem>
        <asp:ListItem runat="server">Parent B</asp:ListItem>
        <asp:ListItem runat="server">Parent C</asp:ListItem>
    </asp:DropDownList>

    <asp:DropDownList ID="ddlChild" runat="server">
        <asp:ListItem runat="server">Please select parent first</asp:ListItem>
    </asp:DropDownList>
</ContentTemplate>
</asp:UpdatePanel>

</form>


code behind

C#
protected void Page_Load(object sender, EventArgs e)
{
    ScriptManager.RegisterStartupScript(this, this.GetType(), "hideMessage", "hideMessage();", true);
}

protected void ddlParent_SelectedIndexChanged(object sender, EventArgs e)
{
    ddlChild.Items.Clear();

    ddlChild.Items.Add(ddlParent.SelectedValue + " 1");
    ddlChild.Items.Add(ddlParent.SelectedValue + " 2");
    ddlChild.Items.Add(ddlParent.SelectedValue + " 3");

    // simulate a delay
    System.Threading.Thread.Sleep(3000);
}
 
Share this answer
 
Comments
sudevsu 18-Mar-15 9:30am    
Awesome. Thank you. I was looking for exactly like this.
Why should not use the Cascading Drop down Box ?

if you use the Cascading Is Fast as your Requirement

refer below link for Cascading Drop down box


http://tusharsangani.blogspot.in/[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900