The server tag is not well formed

G

Guest

I am using an <asp:Repeater> control to generate some checkboxes (C# /
ASP.NET 2.0). The following code works fine:

============================================
<input type="checkbox" name="worksOk" value='<%#
Eval("StoredProcedureID") %>' <%#
isChecked(Eval("StoredProcedureID").ToString()) ? "checked" : "" %> >
============================================


However, when I add [runat="server"] to the <input> tag, an error
message is generated when I try to compile my page ("The server tag is
not well formed"):

============================================
<input runat="server" type="checkbox" name="doesNotWork" value='<%#
Eval("StoredProcedureID") %>' <%#
isChecked(Eval("StoredProcedureID").ToString()) ? "checked" : "" %> >
============================================


Is there any logical explanation for why this happens?


-= Tek Boy =-
 
D

David Wier

Just curious - why are you not using a CheckBox control (one of the ASP.NEt
built in web controls)?
 
G

Guest

Because Microsoft saw fit to remove the Value property of the
<asp:Checkbox> control. You can read more about this at
http://tinyurl.com/uuy47 -- I spent three days trying to format a
collection of checkboxes inside an HTML. And in the end, the solution
was to do exactly what I've been doing with Classic ASP for the past
eight years: get posted-back values from the Request object and then
use in-line preprocessor directives (<%# ... %>) to ensure that the
checkboxes are re-checked.


-= Tek Boy =-
 
B

bruce barker \(sqlwork.com\)

the html controls do not support binding. you are tryng to set a string
binding expression to a bool value.

-- bruce (sqlwork.com)
 
G

Guest

If HTML server controls do not support binding, then how does the
solution MikeS proposed ( http://tinyurl.com/uuy47, post # 6 ) work?

Also, I'm a bit confused what you mean when you say I'm trying "to set
a string binding expression to a bool value" -- what bool value are you
referring to? The isChecked() function returns a boolean value, which
is then used to determine what string is written to the client
("CHECKED" or empty string) by uing the C# ternary operator (
http://www.kdkeys.net/blogs/tgrts_blog/archive/2005/04/19/4576.aspx ).
Or am I missing something


-= Tek Boy =-


the html controls do not support binding. you are tryng to set a string
binding expression to a bool value.

-- bruce (sqlwork.com)

I am using an <asp:Repeater> control to generate some checkboxes (C# /
ASP.NET 2.0). The following code works fine:
============================================
<input type="checkbox" name="worksOk" value='<%#
Eval("StoredProcedureID") %>' <%#
isChecked(Eval("StoredProcedureID").ToString()) ? "checked" : "" %> >
============================================
However, when I add [runat="server"] to the <input> tag, an error
message is generated when I try to compile my page ("The server tag is
not well formed"):
============================================
<input runat="server" type="checkbox" name="doesNotWork" value='<%#
Eval("StoredProcedureID") %>' <%#
isChecked(Eval("StoredProcedureID").ToString()) ? "checked" : "" %> >
============================================
Is there any logical explanation for why this happens?
-= Tek Boy =-
 
D

David Wier

Yes, but the 'Checked' property IS there, with the ASP.Net Checkbox, and
therefore works just fine in its place.
 
G

Guest

Let's consider the example that I posted about (
http://tinyurl.com/uuy47 ). I have a form that lists all user-defined
stored procedures in a SQL Server database. Each stored procedure has
its name displayed to the right of its corresponding checkbox -- the
list is formatted using an HTML table. By "checking off " one or more
checkboxes, the database object IDs that correspond to my selections
are made available via Request.Form upon postback.

How would I transmit the object ID behind each checkbox using the
<asp:CheckBox> control, if it has no Value property? Without those
IDs, the Checked property is meaningless. And as far as
<asp:CheckBoxList> is concerned -- wouldn't I be sacrificing how my
checkboxes are laid out in HTML by using it?


-= Tek Boy =-
 
G

Guest

Which problem -- the one I originally posted about, or what I'm trying
to accomplish?


-= Tek Boy =-
 
G

Guest

Mark --

Yes, that's what I'm trying to do, but without having to rely on having
ViewState enabled. There's more to it -- for example, each row also
has a collapsible DIV tag that allows you to see the stored procedure's
CREATE PROCEDURE statement -- which is why I'm wary of using server
controls, like <asp:CheckBoxList>, that don't afford a lot of
flexibility in how my HTML is laid out.


-= Tek Boy =-
 
M

Mark Rae

Yes, that's what I'm trying to do, but without having to rely on having
ViewState enabled. There's more to it -- for example, each row also
has a collapsible DIV tag that allows you to see the stored procedure's
CREATE PROCEDURE statement -- which is why I'm wary of using server
controls, like <asp:CheckBoxList>, that don't afford a lot of
flexibility in how my HTML is laid out.

OK - good luck, then...
 
Joined
Jul 9, 2009
Messages
1
Reaction score
0
The Answer

You have to use single quotes for the value field when using a repeater to set its value or you will get this error.

<input id="SelectCheckBox" type="checkbox" value='<%# Eval("ItemNumber") %>' runat="server" />

And, for all those who dont get why you would do this, you set an id to the value field of the checkbox so that when you are iterating through the items in the code behind you can get the id numbers of those items that are checked for processing.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top