Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Server Tag is not well formed

Tags:

asp.net

This is so damn stupid but driving me absolutely fing crazy.

<input type="radio" name="OptGroup" id="<%#"rbEmail" + ((Action)Container.DataItem).ID %>" value="<%#((Action)Container.DataItem).ID %>" runat="server" /><label for="<%#"rbEmail" + ((Action)Container.DataItem).ID %>"><%#((Action)Container.DataItem).Action %></label>

What am I doing wrong here! I've also tried:

<input type="radio" name="OptGroup" id='<%#"rbEmail" + ((Action)Container.DataItem).ID %>' value='<%#((Action)Container.DataItem).ID %>' runat="server" /><label for='<%#"rbEmail" + ((Action)Container.DataItem).ID %>'><%#((Action)Container.DataItem).Action %></label>

and

<input type="radio" name="OptGroup" id="<%#'rbEmail' + ((Action)Container.DataItem).ID %>" value="<%#((Action)Container.DataItem).ID %>" runat="server" /><label for="<%#'rbEmail' + ((Action)Container.DataItem).ID %>"><%#((Action)Container.DataItem).Action %></label>

I specifically do not want to use an asp.net radiobutton due to the problems with GroupName it creates while inside a repeater. I want to use a bare radio button and bind its values to my datasource.

like image 998
user72603 Avatar asked Oct 20 '25 11:10

user72603


2 Answers

Do you need to access the control server-side? If not, take off the runat="server", you cannot databind to the ID property for a server control. Not sure if thats the problem, since that should give you a different error

EDIT:

Something like this should suit your purposes..

<asp:Repeater runat="server">
    <ItemTemplate>
        <label><input type="radio" name="rbEmail" value='<%# ((Action)Container.DataItem).ID %>' /><%# ((Action)Container.DataItem).Action %></label>
    </ItemTemplate>
</asp:Repeater>

Then in the postback, you can get the value from Request.Form["rbEmail"]

EDIT2:

Fully tested simple page example..

Default.aspx

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
        <asp:Repeater ID="Repeater1" runat="server">
            <ItemTemplate>
                <label><input type="radio" name="rbEmail" value='<%# Container.DataItem %>' /><%# Container.DataItem %></label>
            </ItemTemplate>
        </asp:Repeater>
        <asp:Button ID="submit" runat="server" OnClick="submit_Click" Text="submit" />
    </form>
</body>
</html>

Default.aspx.cs

using System;

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Repeater1.DataSource = new string[] { "Hello", "World" };
        Repeater1.DataBind();
    }

    protected void submit_Click(object sender, EventArgs e)
    {
        Response.Write(Request.Form["rbEmail"]);
    }
}
like image 145
Adam Avatar answered Oct 25 '25 05:10

Adam


Use single quotes for your html. For example:

<input type='radio' name='OptGroup' id='<%#"rbEmail" + ((Action)Container.DataItem).ID %>' value='<%#((Action)Container.DataItem).ID %>' runat='server' /><label for='<%#"rbEmail" + ((Action)Container.DataItem).ID %>'><%#((Action)Container.DataItem).Action %></label>
like image 37
NotMe Avatar answered Oct 25 '25 05:10

NotMe