[英]javascript server tag not well formed
i wish to pass 2 value to invoke my script but i failed to do so it return me server tag not well formed 我希望传递2值来调用我的脚本,但是我没有这样做,所以返回的服务器标签格式不正确
asp:LinkButton ID="lnkname" runat="server" Text='<%#Eval("movieTitle") %>' Width='500px'
CommandName="cmdLink" PostBackUrl='~/videotest.aspx'
OnClientClick="setSessionValue('video','<%#Eval("movieTitle") %>');"
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: 甚至更好地确保您使用JavaScriptSerializer类正确编码电影标题:
OnClientClick='<%# string.Format("setSessionValue(\"video\", {0});", new JavaScriptSerializer().Serialize(Eval("movieTitle"))) %>'
Yeah, I agree, what a horrible mess are those WebForms. 是的,我同意,那些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")) %>'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.