Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

ASP.NET trigger javascript function from Server side

Posted on 2014-09-04
10
Medium Priority
?
270 Views
Last Modified: 2014-09-19
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("HiddenLoadingImage").style.display = '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.Current.Response.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
0
Comment
Question by:Sam OZ
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
10 Comments
 
LVL 12

Expert Comment

by:Ramkisan Jagtap
ID: 40303165
Please check the default state of the image. I doubt if it is hidden when it is loaded.

or you can try editing your server side script as below:

 System.Web.HttpContext.Current.Response.Write( _
           "<SCRIPT LANGUAGE='JavaScript'> alert('Process Done');
document.getElementById("HiddenLoadingImage").style.display = 'none';     </SCRIPT>")
0
 

Author Comment

by:Sam OZ
ID: 40303574
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
0
 
LVL 12

Expert Comment

by:Ramkisan Jagtap
ID: 40305088
HI Sam,

Just give a try with following:

System.Web.HttpContext.Current.Response.Write( _
            "<SCRIPT type='text/javascript'>  document.getElementById("HiddenLoadingImage").style.display = 'none';
alert('Process Done');
    </SCRIPT>")
0
Understanding Web Applications

Without even knowing it, most of us are using web applications on a daily basis. Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We often confuse these web applications tools for websites.  So, what is the difference?

 

Author Comment

by:Sam OZ
ID: 40305099
Hi Ram,

   I have tried that too,  That is not the solution.
0
 
LVL 12

Expert Comment

by:Ramkisan Jagtap
ID: 40305102
If possible, Can you please post your code here?
0
 

Author Comment

by:Sam OZ
ID: 40305139
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.Current.Response.Write
            or  ScriptManager.RegisterStartupScript
       ( You need to comment out one of thse)
ClientPostFromServer.zip
0
 
LVL 12

Expert Comment

by:Ramkisan Jagtap
ID: 40305159
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("HiddenLoadingImage").style.display = 'none';
           alert("Test Done");
       }

       function DisplayLoadingImage() {
           document.getElementById("HiddenLoadingImage").style.display = "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="DisplayLoadingImage()" />
    </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
0
 

Author Comment

by:Sam OZ
ID: 40305278
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)
0
 
LVL 12

Accepted Solution

by:
Ramkisan Jagtap earned 1500 total points
ID: 40305400
Are you using ajax in your project? If yes you can make a use of Update Progress from ajaxtoolkit dll

http://ajax.net-tutorials.com/controls/updateprogress-control/
0
 

Author Comment

by:Sam OZ
ID: 40311564
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 ?
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days, all we hear about hacktivists took down so and so websites and retrieved thousands of user’s data. One of the techniques to get unauthorized access to database is by performing SQL injection. This article is quite lengthy which gives bas…
Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to choose which pages of your form are visible to your users based on their inputs. The page rules feature provides you with an opportunity to create if:then statements for y…
Learn how to set-up PayPal payment integration in your Wufoo form. Allow your users to remit payment through PayPal upon completion of your online form. This is helpful for collecting membership payments, customer payments, donations, and more.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question