简体   繁体   中英

call javascript function from code behind C# web application

i have a javascript function say 'onclientclicking'.

  <script type="text/javascript">
        function OnClientClicking(button, args) {
            window.location = button.get_navigateUrl();
            args.set_cancel(true);
        }
    </script>

I want to execute this function from code behind. What i am trying to do is based on certain conditions, i need to set the event to telerik button

rad_btn_text.Attributes["OnClientClicking"] = javascript function;

how can it be possible?

regards,

Sivajith S

please try this:

rad_btn_text.OnClientClicking = "OnClientClicking";

It's working on my machine™

You can't "call" client side javascript from the server. That said, you can wire up client side events and emit client side code.

I don't use telrik controls but the asp.net property is onclientclick. Not sure if that is the same on a telerik control and the client side event is onclick.

To call the javascript function from server side:

ScriptManager.RegisterStartupScript(this, typeof(Page), "OnClientClicking", "OnClientClicking();", True);

References

rad_btn_text.Attributes.Add("onclick", "OnClientClicking()")

希望这对你有用

try this. when user click on button the function of "OnClientClicking" will be executed :

rad_btn_text.Attributes["onclick"] = "OnClientClicking()";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM