A
Anonieko
Scenario:
This is a reporting scenario where it takes a while to get
back a response ( report page ) after submit.
I want my user to see some kind of temporary message like
'Processing...' or 'Waiting.. ' after I clicked on a SUBMIT
button to post a web form.
Here is one solution. Anyone who has better?
Create an image button in the page small enough and add a click event
handler for this image button which will redirect to the target page.
The trick is to trigger the click on via javascript on the submit event
handler.
ASPX page has
-------------
...
<P align="center">
<asp:button id="btnSubmit" runat="server" Text="Show
Report"></asp:button>
<BR>
<asp:ImageButton id="triggerControl" runat="server" Width="1px"
Height="1px" ImageUrl="img/unknown.gif" />
<SPAN id="Processing" style="DISPLAY: none">
Please wait while creating report...
</SPAN>
</P>
<SCRIPT type="text/javascript">
var hasSubmitted = 0;
function NoDoubleSubmit() {
var divMsg = document.getElementById('Processing');
if (hasSubmitted == 0) {
hasSubmitted = 1;
divMsg.style.display ='block';
return true;
}
return false;
}
</SCRIPT>
...
THE SERVER ASPX.CS code has these...
-------------------------------------
private void btnSubmit_Click(object sender, System.EventArgs e)
{
bool valid = false;
// Do some validation
if ( valid ) {
triggerControl.Attributes.Add("onclick", "
NoDoubleSubmit();");
}
}
private void triggerControl_Click(object sender,
System.Web.UI.ImageClickEventArgs e)
{
Response.Redirect("ReportTran.aspx");
}
// the extra code above prevents submitting the form twice
This is a reporting scenario where it takes a while to get
back a response ( report page ) after submit.
I want my user to see some kind of temporary message like
'Processing...' or 'Waiting.. ' after I clicked on a SUBMIT
button to post a web form.
Here is one solution. Anyone who has better?
Create an image button in the page small enough and add a click event
handler for this image button which will redirect to the target page.
The trick is to trigger the click on via javascript on the submit event
handler.
ASPX page has
-------------
...
<P align="center">
<asp:button id="btnSubmit" runat="server" Text="Show
Report"></asp:button>
<BR>
<asp:ImageButton id="triggerControl" runat="server" Width="1px"
Height="1px" ImageUrl="img/unknown.gif" />
<SPAN id="Processing" style="DISPLAY: none">
Please wait while creating report...
</SPAN>
</P>
<SCRIPT type="text/javascript">
var hasSubmitted = 0;
function NoDoubleSubmit() {
var divMsg = document.getElementById('Processing');
if (hasSubmitted == 0) {
hasSubmitted = 1;
divMsg.style.display ='block';
return true;
}
return false;
}
</SCRIPT>
...
THE SERVER ASPX.CS code has these...
-------------------------------------
private void btnSubmit_Click(object sender, System.EventArgs e)
{
bool valid = false;
// Do some validation
if ( valid ) {
triggerControl.Attributes.Add("onclick", "
NoDoubleSubmit();");
}
}
private void triggerControl_Click(object sender,
System.Web.UI.ImageClickEventArgs e)
{
Response.Redirect("ReportTran.aspx");
}
// the extra code above prevents submitting the form twice