Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Form submit event is not capturing OnSelectedIndexChanged?

I have a button and a dropdownlst

enter image description here

And I have this script :

$("form").submit(function (e)
    {
        $('#divOverlay').show();
        });

My Goal :

When a form submits , I need to show a "loading div" :

Question :

When I press the button it does show me the div (the gray div which blinks for a second):

enter image description here

But when I change index on the dropdownlist :

<asp:DropDownList runat="server" OnSelectedIndexChanged="OnSelectedIndexChanged" AutoPostBack="True">
    <asp:ListItem Value="a"> a</asp:ListItem>
        <asp:ListItem Value="b">b</asp:ListItem>
</asp:DropDownList>

It does submit bUt I dont see the div :

enter image description here

Why does the $("form").submit(function (e) does not capture this postback which occurs after selected index change ? ?

NB :

Fiddler shows both events (pressing the button && changing index) as a POST command

What is the structure of the file ? ( psuedo) :

<html  >
<head>
 ...     
</head>
<body>
    <div id='divOverlay'>  
       ...
    </div>

        <form id="form1" runat="server"  >
            <asp:Button runat="server" Text="sssssss"/>
        <asp:DropDownList runat="server" OnSelectedIndexChanged="OnSelectedIndexChanged" AutoPostBack="True">
            ...
        </asp:DropDownList>

        </form>


        <script type="text/javascript">
            $(function()
                {
                    $("form").submit(function (e)
                    {
                            $('#divOverlay').show();
                    });
                });

        </script>
</body>
</html>

Can you show the difference between both requests which sent to the server ? **Yes.**

The right side is when index is changed and the left pane is for button press

enter image description here

like image 583
Royi Namir Avatar asked Aug 26 '13 14:08

Royi Namir


2 Answers

There is an ASP.NET's method: ClientScript.RegisterOnSubmitStatement, that lets you run a JavaScript statement each time the HtmlForm is submitted

ClientScript.RegisterOnSubmitStatement(this.GetType(), "divOverlayShow", "$('#divOverlay').show();");
like image 197
Oleg Grishko Avatar answered Nov 09 '22 00:11

Oleg Grishko


I guess the autopostback behaviour is to submit the form through javascript and a call to __doPostBack(), which does not trigger the submit event.

You may try :

<asp:DropDownList onchange="$('#divOverlay').show();" runat="server" OnSelectedIndexChanged="OnSelectedIndexChanged" AutoPostBack="True">
like image 22
jbl Avatar answered Nov 08 '22 22:11

jbl