开发者

Accessing code behind property in server tags

Is it possible to access a code behind p开发者_如何转开发roperty for a server tag? I have a property on my code behind page that i want to pass into a javascript function i.e.

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

So i want to be able to get the variable out of my code behind page and pass it to the "moveToNextPage()" function. Is this possible?


If your code behind value is public or protected then you can try this (assuming your variable is called example):

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


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

Make sure your yourproperty is public


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

Important change would be <%# instead of <%=. In order for this to work, you need to call myRadioButton.DataBind() somewhere in code behind

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜