user335160
user335160

Reputation: 1362

Form tag is not well formed (control Id)

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" />

Upvotes: 0

Views: 1654

Answers (4)

Kris van der Mast
Kris van der Mast

Reputation: 16613

Make this

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

to this:

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

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>

and in codebehind:

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

phTest.Controls.Add(image);

Upvotes: 2

abatishchev
abatishchev

Reputation: 100268

If you're using .NET 4.0 set ClientIDMode=Static or change ID not in markup but in code-behind.

And use instead of if you need access it from code-behind.

Upvotes: 0

hallie
hallie

Reputation: 2845

How about this?

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

or try to remove the runat="server" since your img tag is not a server control

Upvotes: 0

Thea
Thea

Reputation: 8067

I got a similar problem and I solved it like this:

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

The reason for this is that the expression between <%# %> cannot be evaluated if it is not in single quotes.

Upvotes: 0

Related Questions