Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
hi,
 
i want to call javascript method from code behind after exception is caught in finally block
i.e.
try
{
 //my code here
}
catch()
{
 //msg
}
finally
{
 
// calling javascript method here

}
Posted 28-May-12 20:38pm
Edited 28-May-12 20:42pm
member6016.1K
v3
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

I did a similar thing were I call JavaScript alert box from code behind. perhaps you can also do something like this
 
check out this and make the changes as per your need to achieve what you want to do.
 
A Windows Form like MessageBox for ASP.NET Website[^]
  Permalink  
Comments
Prasad_Kulkarni at 29-May-12 7:23am
   
Good one +5!
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

hi,
try like this:
 
        try
        {
            //my code here
        }
        catch (Exception ee)
        {
           // throw ee;
        }
        finally
        {
            ScriptManager.RegisterClientScriptBlock(Page, this.GetType(), "CallJS", "JSFunctionName();", true);
        }
  Permalink  
v2
Comments
Rahul Rajat Singh at 29-May-12 1:48am
   
This is also a very good answer +5
Member 8861818 at 29-May-12 2:33am
   
tried but not calling javascript method from finally block
tanweer akhtar at 29-May-12 2:49am
   
if you are using Script Manage on your page then the above answer will work other wise you need to add this one
Page.ClientScript.RegisterStartupScript(this.GetType(), "CallJS", "JSFunctionName();", true);
amolpatil2243 at 29-May-12 8:11am
   
my 5+
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

you can try such as :
finally
{
string script = "<script language="'javascript'">yourFunction();</script>";
 Page.RegisterClientScriptBlock("xxx", script);
}
 
and the function should be in the head section of page such as:
<script type="text/javascript">
        function yourFunction() {
            alert("Hai");
            return;           
        }
    </script>
 
for more on this topic refer:http://www.codedigest.com/Articles/ASPNET/314_Multiple_Ways_to_Call_Javascript_Function_from_CodeBehind_in_ASPNet.aspx[^]
  Permalink  
v5
Comments
Member 8861818 at 29-May-12 2:34am
   
tried but not calling javascript method from finally block
member60 at 29-May-12 7:09am
   
k! check my solution again I changed it.It should work.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

try
      {
          //my code here
      }
      catch (Exception ee)
      {
         // throw ee;
      }
      finally
      {
 
          ScriptManager.RegisterClientScriptBlock(Page, this.GetType(), "CallJSFunction", "YourFunctionName()", true);
      }
 

you can write your js function which you can set in a string variable like this
 

try
      {
          //my code here
      }
      catch (Exception ee)
      {
         // throw ee;
      }
      finally
      {
string jsFunction="alert('Process comlete');"
          ScriptManager.RegisterClientScriptBlock(Page, this.GetType(), "CallJSFunction", "jsFunction", true);
      }
  Permalink  
v2
Comments
Member 8861818 at 29-May-12 2:34am
   
tried but not calling javascript method from finally block
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

 
try
{
}
catch(exception ex)
{
ScriptManager.RegisterClientScriptBlock(Page, this.GetType(), "Alert", "<script type="Text/javascript">alert(' & ex.message &')</script>", true);
}
 
 
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Kornfeld Eliyahu Peter 169
1 George Jonsson 145
2 Zoltán Zörgő 139
3 PIEBALDconsult 130
4 OriginalGriff 120
0 OriginalGriff 6,165
1 DamithSL 4,658
2 Maciej Los 4,107
3 Kornfeld Eliyahu Peter 3,649
4 Sergey Alexandrovich Kryukov 3,382


Advertise | Privacy | Mobile
Web02 | 2.8.141220.1 | Last Updated 29 May 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100