且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

设置控件的属性时,ASP.NET引号字符编码导致问题

更新时间:2023-02-16 16:39:57

我想你可能需要在你的作业都字符串的@,并删除斜杠:

I think you might need the @ on both string literals in your assignment, and remove the slashes:

mycontrol.stringparameterforjscript = @"document.getElementById('" + myotherparam + @"').value = 'Hello'";

修改

我怎么做的:

在在.aspx:

<asp:Textbox ID="tbTest" runat="server" TextMode="MultiLine" />

在code:

protected void Page_Load(object sender, EventArgs e)
{
    string myotherparam = "paramval";
    tbTest.Attributes.Add("onfocus", @"document.getElementById('" + myotherparam + @"').value = 'Hello'");
}

结果输出:

<textarea name="tbTest" rows="2" cols="20" id="tbTest" onfocus="document.getElementById('paramval').value = 'Hello'"></textarea>