Reputation: 107
i wish to pass 2 value to invoke my script but i failed to do so it return me server tag not well formed
asp:LinkButton ID="lnkname" runat="server" Text='<%#Eval("movieTitle") %>' Width='500px'
CommandName="cmdLink" PostBackUrl='~/videotest.aspx'
OnClientClick="setSessionValue('video','<%#Eval("movieTitle") %>');"
Upvotes: 0
Views: 1093
Reputation: 1039588
Try like this:
OnClientClick='<%# string.Format("setSessionValue(\"video\", {0});", Eval("movieTitle")) %>'
Or even better ensure that you properly encode the movie title using the JavaScriptSerializer class:
OnClientClick='<%# string.Format("setSessionValue(\"video\", {0});", new JavaScriptSerializer().Serialize(Eval("movieTitle"))) %>'
Yeah, I agree, what a horrible mess are those WebForms. You would probably externalize this into a function in your code behind:
public string FormatJs(object movieTitle)
{
return string.Format(
"setSessionValue(\"video\", {0});",
new JavaScriptSerializer().Serialize(movieTitle)
);
}
and then:
OnClientClick='<%# FormatJs(Eval("movieTitle")) %>'
Upvotes: 4