Skip to content Skip to sidebar Skip to footer

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 asp:LinkButton ID='lnkname' runat='server' Text='<%#Eval('movieTitle') %

Solution 1:

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:

publicstringFormatJs(object movieTitle)
{
    returnstring.Format(
        "setSessionValue(\"video\", {0});", 
        new JavaScriptSerializer().Serialize(movieTitle)
    );
}

and then:

OnClientClick='<%# FormatJs(Eval("movieTitle")) %>'

Post a Comment for "Javascript Server Tag Not Well Formed"