发布字段中带有 html 标签的表单时出现错误
我正在使用 Ajax 控制工具包 3.5。我有一个这样的表格:
<body>
<form id="form1" runat="server">
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</asp:ToolkitScriptManager>
<div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
此页面的相关代码隐藏是这样的:
protected void Button1_Click(object sender, EventArgs e)
{
Label1.Text = TextBox1.Text;
}
当我将“foo”写入 TextBox1 时,它会成功地将其复制到 Label1 中。但是,如果我使用一些 HTML 标签(例如“foo”)将任何文本写入文本框中我在 IE 状态栏中收到以下 Javascript 错误:
我该如何解决此问题?
提前致谢。
I am using Ajax Control Toolkit 3.5. I have a form like this:
<body>
<form id="form1" runat="server">
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</asp:ToolkitScriptManager>
<div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
And related codebehind of this page is this:
protected void Button1_Click(object sender, EventArgs e)
{
Label1.Text = TextBox1.Text;
}
When I write for example "foo" into the TextBox1 it succesfully copies that into Label1. But if I write any text into the textbox with some HTML tags like "<b>foo</b>" i get following Javascript error in IE statusbar:
How can I solve this?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
发布这个问题后,我想到了从 UpdatePanel 中取出表单字段并重试相同操作的想法。宾果!它抛出以下异常:
看到此错误后,将以下代码添加到 <%@ Page %> 中:页面的部分解决了这个问题。
希望这对其他人有帮助......
Just after posting this question, the idea of taking the form fields out of UpdatePanel and retrying the same operation came to my mind. Bingo! It throws the following exception:
After seeing this error, adding the following code to the <%@ Page %> section of the page solved the problem.
Hope this helps to others...