Way to call code-behind event

Posted on 2014-08-24
Last Modified: 2014-08-27
I want to call one code-behind event within one javascript event. Can you please show with one example to this?
Question by:HuaMinChen
    LVL 16

    Expert Comment

    by:Easwaran Paramasivam
    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 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.

    LVL 10

    Author Comment

    Many thanks Easwaran.

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

    Open in new window

    within server-side method?
    LVL 10

    Author Comment

    I have tried it and have got that it is no possible to execute ClientScript within server-side method. How to resolve this?
    LVL 16

    Accepted Solution

    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>");


    ClientScript.RegisterClientScriptBlock(this.GetType(), "unique_key", "yourjsfunction()", true);
    LVL 10

    Author Closing Comment

    I really don't have time to confirm if this is surely the answer or not.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
    OverviewThis article demonstrates a simple search form using AJAX. The purpose of the article is to demonstrate how to use the same code to render a page and javascript (JQuery) and AJAX to make subsequent calls to refine the results. The princip…
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    779 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

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now