Question

i'm trying to binding a variable data to a input control as the value of the property,but the vs2010 throw a warning:"validation (XHTML 1.0 Transitional):Attribute values must be enclosed in quotation marks."

can anyone tell me how to fix it?

here is my code:

<input type="button" id="btn_jump" runat="server" onclick=<%#"javascript:window.location.href='Default.aspx?var=" + m_id + "'" %> value="jump"/>

i've tried these below but get an error:"Server tag is not correctly formatted"

<input type="button" id="btn_jump" runat="server"
onclick="<%#"javascript:window.location.href='Default.aspx?var=" + m_id + "'" %>" value="jump"/>

<input type="button" id="btn_jump" runat="server"
onclick='<%#"javascript:window.location.href='Default.aspx?var=" + m_id + "'" %>' value="jump"/>

here is the correct solution:

method 1:

btn_jump.Attributes.Add("onclientclick","javascript:window.location.href='Default.aspx?var=" + m_id + "'");

method 2:

<input type="button" id="btn_jump" runat="server"
onclick='<%#"javascript:window.location.href=\"Default.aspx?var=" + m_id + "\"" %>' value="jump"/>
Was it helpful?

Solution

You should use OnclientClick. Do the below approach.

<input type="button" id="btn_jump" runat="server"
onclientclick='redirect(<%#Eval("m_id")%>)' value="jump"/>


function redirect(id) {
  location.href = 'Default.aspx?var=' + id;
}

OR use Eval placeholder

<input type="button" id="btn_jump" runat="server"
onClientClick='<%# Eval("m_id", "location.href=Default.aspx?var={0}") %>' value="jump"/>

Or add onclientclick Attributes from code behind

btn_jump.Attributes.Add("onclientclick","javascript:window.location.href='Default.aspx?var=" + m_id + "'");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top