开发者

How to combine C# code with JavaScript code in onclick?

开发者 https://www.devze.com 2023-01-28 02:52 出处:网络
I want to use C# code and JavaScript in the same onclientclick event. <asp:Link开发者_如何学PythonButton ID=\"lbTest\" runat=\"server\" Text=\'<%#Text%>\'

I want to use C# code and JavaScript in the same onclientclick event.

<asp:Link开发者_如何学PythonButton ID="lbTest" runat="server" Text='<%#Text%>' 
    OnClientClick='<%#string.Format("passAccessory(\"{0}\");", Eval("Ref"))%>; window.close();' />

But it doesn't work. How to do that?

Thanks.


What are you reying to acheive? Do you wnat to call a javascript function which uses some of server side variables and close at the end.

function MyF()
{
    var myvar = '<%= myC#Var %>';
    ....do something

   window.close()

}


<asp:LinkButton ID="lbTest" runat="server"  OnClientClick='MyF()' /> 


add an OnClientClick and OnClick events. The OnClientClick event will be executed first then the OnClick event.

<asp:LinkButton ID="lbTest" runat="server" OnClientClick="test()" OnClick="lbTest_Click" /> 
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号