简体   繁体   English

如何在 asp:Radiobutton 中调用 Javascript 函数?

[英]How to Call Javascript function in asp:Radiobutton?

I have a Radio button in a Gridview and when we click on the button, i'm calling function in the code behind file(user control).我在 Gridview 中有一个单选按钮,当我们单击该按钮时,我在文件背后的代码(用户控件)中调用函数。 Before that i need to implement need call a javascript function to confirm about change.在此之前,我需要实现需要调用 javascript 函数来确认更改。 I tried onclick, OnClientClick, OnSelect and none of them worked as expected.我尝试了 onclick、OnClientClick、OnSelect,但它们都没有按预期工作。

<asp:RadioButton ID="ratiobuttonChoose" runat="server" AutoPostBack="true" 
                                    OnCheckedChanged="Selected"/>

Can someone, please suggest me how to do this one.有人可以,请建议我如何做到这一点。

Add a script on Page_Load in code behind:在 Page_Load 后面的代码中添加一个脚本:

ratiobuttonChoose.Attributes.Add("onclick", "clientJsFunction()");

Reference: MSDN参考: MSDN

You can add onclick direct on your tag (VisualStudio don't suggest but it works):您可以直接在您的标签上添加 onclick(VisualStudio 不建议,但它有效):

<asp:RadioButton ID="ratiobuttonChoose" runat="server" AutoPostBack="true" 
    OnCheckedChanged="Selected" onclick="alert('Clicked!');" />

You can also use jQuery, see here .您也可以使用 jQuery,请参见此处

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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