2010-12-10 70 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()在代碼後面的代碼