I have created a Website Project in VS2010. My Controls are not rendered correctly. The JS that is produced is not correctly formatted. Here is an example:
protected void Page_PreRender(object sender, EventArgs e)
{
if (!IsPostBack)
{
objListBox.Attributes.Add("onchange", "Control_doPostBack('" + objListBox.ClientID + "','ListBox_OnClick'); return false;");
objListBox.Attributes.Add("onblur", "Control_doPostBack('" + trListbox.ClientID + "','ListBox_OnBlur'); return false;");
img.Attributes.Add("onclick", "Control_doPostBack('" + trListbox.ClientID + "','IMG_OnClick'); return false;");
}
}
and the responding control is rendered as:
<select size="4" name="ctl00$PlaceHolder_Content$drop$objListBox" onchange="Control_doPostBack('PlaceHolder_Content_drop_objListBox','ListBox_OnClick'); return false;setTimeout('__doPostBack(\'ctl00$PlaceHolder_Content$drop$objListBox\',\'\')', 0)" id="PlaceHolder_Content_drop_objListBox" onblur="Control_doPostBack('PlaceHolder_Content_drop_trListbox','L开发者_开发问答istBox_OnBlur'); return false;" style="position:absolute;">
</select>
As you can see, the ' are rendered to '
which screwes up the Browser.
Is there a tweak to msbuild or inside the project properties?
Any help is highly appreciated.
Out of curiosity, what renders if you change
objListBox.Attributes.Add("onchange", "Control_doPostBack('" + objListBox.ClientID + "','ListBox_OnClick'); return false;");
to
objListBox.Attributes.Add("onchange", "Control_doPostBack(\'" + objListBox.ClientID + "\',\'ListBox_OnClick\'); return false;");
?
The browser is in error. name="a'b'c"
and name="a'b'c"
are two completely equivalent ways of specifying an attribute whose value is a'b'c
.
精彩评论