Sam OZ
asked on
ASP.NET trigger javascript function from Server side
hi Experts,
On the click of a button , some server side process is happening . I already have a small piece of javascript ( runs at on clientclick) to show a 'waiting image' .
The javascript line of code is
document.getElementById("H iddenLoadi ngImage"). style.disp lay = 'block';
(The defualt display state of the Image is hidden and it is shows up only when the button is clicked)
Also, when the server processing is over, I have a server side line of code to show a message that the processing is done
System.Web.HttpContext.Cur rent.Respo nse.Write( _
"<SCRIPT LANGUAGE='JavaScript'> alert('Process Done')</SCRIPT>")
But my issue is - The Waiting image is still visible when the Alert of "Process Done" pops up.
How can I hide the image first and then show the Alert ?
Thanks
Sam
On the click of a button , some server side process is happening . I already have a small piece of javascript ( runs at on clientclick) to show a 'waiting image' .
The javascript line of code is
document.getElementById("H
(The defualt display state of the Image is hidden and it is shows up only when the button is clicked)
Also, when the server processing is over, I have a server side line of code to show a message that the processing is done
System.Web.HttpContext.Cur
"<SCRIPT LANGUAGE='JavaScript'> alert('Process Done')</SCRIPT>")
But my issue is - The Waiting image is still visible when the Alert of "Process Done" pops up.
How can I hide the image first and then show the Alert ?
Thanks
Sam
ASKER
Hi Ramkisan,
I am not sure I stated my issue clearly . When the alert pops up the image is visible. But if I click ok, the image becomes invisible
I already tired the code you suggested . It doesn't work , unfortunately
I am not sure I stated my issue clearly . When the alert pops up the image is visible. But if I click ok, the image becomes invisible
I already tired the code you suggested . It doesn't work , unfortunately
HI Sam,
Just give a try with following:
System.Web.HttpContext.Cur rent.Respo nse.Write( _
"<SCRIPT type='text/javascript'> document.getElementById("H iddenLoadi ngImage"). style.disp lay = 'none';
alert('Process Done');
</SCRIPT>")
Just give a try with following:
System.Web.HttpContext.Cur
"<SCRIPT type='text/javascript'> document.getElementById("H
alert('Process Done');
</SCRIPT>")
ASKER
Hi Ram,
I have tried that too, That is not the solution.
I have tried that too, That is not the solution.
If possible, Can you please post your code here?
ASKER
Hi Ram,
Please see the attachment for the test code . ( You need to have an image by name Spinner.jpg under the folder \images )
Just a correction in my code ---
Use either System.Web.HttpContext.Cur rent.Respo nse.Write
or ScriptManager.RegisterStar tupScript
( You need to comment out one of thse)
ClientPostFromServer.zip
Please see the attachment for the test code . ( You need to have an image by name Spinner.jpg under the folder \images )
Just a correction in my code ---
Use either System.Web.HttpContext.Cur
or ScriptManager.RegisterStar
( You need to comment out one of thse)
ClientPostFromServer.zip
Hello Sam,
Change you code as below:
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<script type="text/javascript" language="javascript">
function AlertClient() {
document.getElementById("H iddenLoadi ngImage"). style.disp lay = 'none';
alert("Test Done");
}
function DisplayLoadingImage() {
document.getElementById("H iddenLoadi ngImage"). style.disp lay = "block";
}
</script>
<title></title>
</head>
<body onload="AlertClient()">
<form id="form1" runat="server">
<div>
<img id='HiddenLoadingImage' src="Images/Spinner.jpg" style="display:none"/>
<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="DisplayLoad ingImage() " />
</div>
</form>
</body>
</html>
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
WasteTime()
Dim strMessage As String
strMessage = "This is test"
End Sub
Sub WasteTime()
Dim i, j, k As Integer
For i = 0 To 1000
For j = 0 To 1000
For k = 0 To 100
Next
Next
Next
End Sub
Change you code as below:
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<script type="text/javascript" language="javascript">
function AlertClient() {
document.getElementById("H
alert("Test Done");
}
function DisplayLoadingImage() {
document.getElementById("H
}
</script>
<title></title>
</head>
<body onload="AlertClient()">
<form id="form1" runat="server">
<div>
<img id='HiddenLoadingImage' src="Images/Spinner.jpg" style="display:none"/>
<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="DisplayLoad
</div>
</form>
</body>
</html>
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
WasteTime()
Dim strMessage As String
strMessage = "This is test"
End Sub
Sub WasteTime()
Dim i, j, k As Integer
For i = 0 To 1000
For j = 0 To 1000
For k = 0 To 100
Next
Next
Next
End Sub
ASKER
Hi Ram,
It can't happen on the Onload in the client . it should happen only after the Button is clicked ( In my actual code there are many other controls)
Also , Infact, strictly speaking , the Alert should come with the value of a server variable ( But that is not the real problem I face)
It can't happen on the Onload in the client . it should happen only after the Button is clicked ( In my actual code there are many other controls)
Also , Infact, strictly speaking , the Alert should come with the value of a server variable ( But that is not the real problem I face)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi Ram & other Experts,
AJAX is not used in this project , unfortunately ( This is a revamp project ) . Also I am a little naive with AJAX
Is there really a way to do this with no AJAX ?
AJAX is not used in this project , unfortunately ( This is a revamp project ) . Also I am a little naive with AJAX
Is there really a way to do this with no AJAX ?
or you can try editing your server side script as below:
System.Web.HttpContext.Cur
"<SCRIPT LANGUAGE='JavaScript'> alert('Process Done');
document.getElementById("H