I have a button
and a dropdownlst
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):
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 :
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
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();");
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">
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With