2010-12-10 66 views
0

是否可以访问服务器标签属性后面的代码? 我对网页的背后我的代码的属性,我要进入一个JavaScript函数,即在服务器标签中访问属性背后的代码

<asp:RadioButton onclick="moveToNextPage()" class="inputcell" Runat="server" ID="myRadioButton" Text="No"></asp:RadioButton> 

所以我希望能够得到可变出来的页面背后我的代码,并把它传递给“moveToNextPage ()“功能。这可能吗?

回答

2

如果后面值为你的代码是publicprotected那么你可以试试这个(假设你的变量称为example):

<asp:RadioButton onclick='<%= string.Format("moveToNextPage({0})", example) %>' class="inputcell" Runat="server" ID="myRadioButton" Text="No"></asp:RadioButton> 
+0

我试过这个,它似乎并没有工作。我在我的财产上放置了一个断点,我正在查询,并且它从未受到影响。应该是? – Ben 2010-12-10 16:27:15

+0

如果您正在传递字符串值moveToNextPage('{0}') – rtpHarry 2010-12-10 16:33:01

+0

如果您查看源代码,您是否在onclick事件处理程序中看到任何内容,则可能需要在其周围包装''? – rtpHarry 2010-12-10 16:33:57

1
<asp:RadioButton onclick='<%= string.Format("moveToNextPage({0})", yourproperty) %>' class="inputcell" Runat="server" ID="myRadioButton" Text="No"></asp:RadioButton> 

确保您yourproperty是公共

+0

我试过了,它似乎没有工作。我在我的财产上放置了一个断点,我正在查询,并且它从未受到影响。应该是? – Ben 2010-12-10 16:26:53

+0

)”class =“inputcell”Runat =“server”ID =“myRadioButton”Text =“No”>尝试提醒javascript函数 – 2010-12-10 16:32:18

0
<asp:RadioButton onclick='<%# string.Format("moveToNextPage({0})", yourproperty) %>' class="inputcell" Runat="server" ID="myRadioButton" Text="No"></asp:RadioButton> 

重要的变化将是<%#而不是<%=。为了这个工作,你需要调用myRadioButton.DataBind()在代码后面的代码