我想將c#綁定變量傳遞給javascript函數。這裏是我的代碼:如何將csharp綁定變量傳遞給Javascript函數
<asp:LinkButton ID="lbID" runat="server" Text="<%#Text%>" OnClientClick="passAccessory('<%#Bind(variable)%>'); "></asp:LinkButton>
但它總是會產生一個錯誤:「htmlfile:未實現」。
和代碼不intepreted onclick="passAccessory('<%#Bind(variable)%>');"
有誰知道如何解決呢?
感謝。
編輯:我已經改變了代碼
<asp:LinkButton ID="lbID" runat="server" Text="<%#Text%>" OnClientClick="passAccessory('<%# Eval("lblTest.ClientID") %>');"></asp:LinkButton>
這是它的相關的代碼,它使用lblTest.ClientID
<asp:Label ID="lblTest" runat="server" Text='<%#Bind("reference")%>' />
但是我收到一個錯誤:HttpException. Databinding ... does not contain a property with the name lblTest
。我的代碼有問題嗎?
編輯:這些帖子給了我一個線索。
http://www.west-wind.com/Weblog/posts/5364.aspx
I am trying to learn how to bind an IEnumerable LINQ collection to a repeater
現在我必須要使用
<asp:LinkButton ID="lbTest" runat="server" Text='<%#Text%>' OnClientClick='<%#string.Format("passAccessory(\"{0}\");", Eval("Ref"))%>'></asp:LinkButton>
它會產生一個錯誤:`CS0103:名稱「綁定」不存在當前context` – 2010-11-30 08:56:05
我已經更新了我的答案存在,也許這個作品。自從使用webforms以來,大約在1.5年前。 – Gidon 2010-11-30 09:05:45
雖然你的答案是正確的,但這種類型的語法可以在數據綁定控件(如GridView,Repeater或ListView)內部應用。看起來OP沒有他的LinkButton在這樣的控制之下,還是他? :S – 2010-11-30 09:14:04