[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 160
  • Last Modified:

Way to call code-behind event

Hi,
I want to call one code-behind event within one javascript event. Can you please show with one example to this?
0
HuaMinChen
Asked:
HuaMinChen
  • 3
  • 2
1 Solution
 
Easwaran ParamasivamCommented:
What method you would like to call and why? Whatever you do in server side try to perform in client side if possible. Otherwise please try below solution.

 You can't call the asp.net life cycle methods such as page_load. Instead, you could write the server side method as webservice and call it in either javascript or ajax. Following links could be helpful.

http://aspsnippets.com/Articles/Calling-server-side-methods-using-JavaScript-and-JQuery-in-ASP.Net.aspx

http://www.morgantechspace.com/2014/01/Call-Server-Side-function-from-JavaScript-in-ASP-NET.html

HTH.
0
 
HuaMinChenBusiness AnalystAuthor Commented:
Many thanks Easwaran.

Is it possible to call this
            ClientScript.RegisterStartupScript(this.GetType(), "script", s, true);

Open in new window


within server-side method?
0
 
HuaMinChenBusiness AnalystAuthor Commented:
I have tried it and have got that it is no possible to execute ClientScript within server-side method. How to resolve this?
0
 
Easwaran ParamasivamCommented:
Assume that yourjsfunction() is valid javascript function in your page.  Use one of the method to execute it.

Page.RegisterStartupScript("unique_key", "<script type=\"text/javascript\">yourjsfunction()</script>");

or

ClientScript.RegisterClientScriptBlock(this.GetType(), "unique_key", "yourjsfunction()", true);
0
 
HuaMinChenBusiness AnalystAuthor Commented:
I really don't have time to confirm if this is surely the answer or not.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now