表单标签格式不正确(控件ID) [英] Form tag is not well formed (control Id)

查看:63
本文介绍了表单标签格式不正确(控件ID)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,有人可以帮我解决我的问题.我向图像控件的ID属性分配了一个动态ID.问题是我收到一个错误消息,说"form标签格式不正确".我将双引号替换为单引号或删除了这些引号,但出现了相同的错误.我该如何解决这个问题?顺便说一下,我使用的是C#语言.

Hi can anyone help me regarding my problem. I assigned a dynamic Id into the ID property of an image control. The problem is I got an error saying "form tag is not well formed". I replaced the double quote into a single or removed those quotes but I got the same error. How can I resolved this issue? By the way I used c# language.

<img ID="<%# DataBinder.Eval(Container.DataItem, "Id")%>" runat="server" />

推荐答案

做到这一点

<img ID="<%# DataBinder.Eval(Container.DataItem, "Id")%>" runat="server" />

对此:

<img ID='<%# DataBinder.Eval(Container.DataItem, "Id")%>' runat="server" />

更新:显然不可能做到这一点.我在html图像和Image服务器控件中都进一步在测试应用程序中进行了尝试.经过进一步思考并喝了些咖啡之后,就可以说不能这样设置ID了.您如何在代码隐藏中没有ID的东西上设置属性?

Update: apparently it's indeed not possible to do this. I tried in a test application further with both the html image and Image server control. After thinking a bit further, and taking some coffee, it kind of makes sense that an ID cannot be set as such. How would you set properties on something without an ID in codebehind?

但是,您可以做的另一种方法是:

An alternative way what you can do however is this:

<form id="form1" runat="server">
    <div>
        <asp:PlaceHolder runat="server" ID="phTest"></asp:PlaceHolder>
    </div>
</form>

及其后的代码:

HtmlImage image = new HtmlImage();
image.ID = "SomeRandomId";
image.Src = "urltosomeimage";

phTest.Controls.Add(image);

这篇关于表单标签格式不正确(控件ID)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆