I want to pass c# binding variable to javascript function. Here is my code:
<asp:LinkButton ID="lbID" runat="server" Text="<%#Text%>" OnClientClick="passAccessory('<%#Bind(variable)%>'); "></asp:LinkButton>
But it always generates an error : "htmlfile: Not implemented".
And the code is not intepreted onclick="passAccessory('<%#Bind(variable)%>');"
Does anyone knows how to solve it ?
Thanks.
Edit: I have changed the code to
<asp:LinkButton ID="lbID" runat="server" Text="<%#Text%>" OnClientClick="passAccessory('<%# Eval("lblTest.ClientID") %>');"></asp:LinkButton>
And this is the code it's related to, it uses the lblTest.ClientID
<asp:Label ID="lblTest" runat="server" Text='<%#Bind("reference")%>' />
But i received an error: HttpException. Databinding ... does not contain a property with the name lblTest
. Is there any wrong with my code.
Edit: These posts gave me a clue.
.aspx
I am trying to learn how to bind an IEnumerable LINQ collection to a repeater
Now i have want to use
<asp:LinkButton ID="lbTest" runat="server" Text='<%#Text%>' OnClientClick='<%#string.Format("passAccessory(\"{0}\");", Eval("Ref"))%>'></asp:LinkButton>
I want to pass c# binding variable to javascript function. Here is my code:
<asp:LinkButton ID="lbID" runat="server" Text="<%#Text%>" OnClientClick="passAccessory('<%#Bind(variable)%>'); "></asp:LinkButton>
But it always generates an error : "htmlfile: Not implemented".
And the code is not intepreted onclick="passAccessory('<%#Bind(variable)%>');"
Does anyone knows how to solve it ?
Thanks.
Edit: I have changed the code to
<asp:LinkButton ID="lbID" runat="server" Text="<%#Text%>" OnClientClick="passAccessory('<%# Eval("lblTest.ClientID") %>');"></asp:LinkButton>
And this is the code it's related to, it uses the lblTest.ClientID
<asp:Label ID="lblTest" runat="server" Text='<%#Bind("reference")%>' />
But i received an error: HttpException. Databinding ... does not contain a property with the name lblTest
. Is there any wrong with my code.
Edit: These posts gave me a clue.
http://www.west-wind./Weblog/posts/5364.aspx
I am trying to learn how to bind an IEnumerable LINQ collection to a repeater
Now i have want to use
<asp:LinkButton ID="lbTest" runat="server" Text='<%#Text%>' OnClientClick='<%#string.Format("passAccessory(\"{0}\");", Eval("Ref"))%>'></asp:LinkButton>
Share
edited May 23, 2017 at 11:44
CommunityBot
11 silver badge
asked Nov 30, 2010 at 8:39
SUN JiangongSUN Jiangong
5,31216 gold badges60 silver badges77 bronze badges
3 Answers
Reset to default 5You don't want a two way bind, but rather an Eval.
<asp:LinkButton ID="lbID" runat="server" Text="<%#Text%>" OnClientClick='passAccessory(\"<%# Eval("variable") %>\");'></asp:LinkButton>
I didn't do ASP.NET webforms for along time, but I believe it should be like this:
OnClientClick="<%# string.Format("passAccessory('{0}');", Container.DataItem("variable")) %>"
You can do this easily by changing the OnClientClick event from Code-Behind.
lbID.OnClientClick = "passAccessory(' " + variable + "')";