Problem with Control Attributes in Repeaters

PWNettle

Well-known member
Joined
Jun 2, 2003
Messages
128
Location
Phoenix, AZ
Hmm, I thought I deleted this...

Im having a problem with some attributes/events placed inside controls in a repeater.

For example, Im trying to place a RequiredFieldValidator where I want to set the error message including the DataItem like this:

errormessage=<%# DataBinder.Eval(Container, "DataItem.Name")%> is a Required Field! runat="server">

What happens is that the single quotes get converted to double quotes, and the double quotes surrounding DataItem.Name get converted to HTML quote codes (& q u o t ; - without the spaces - cant seem to find codes to display code without HTML interpretation on this forum!).

It appears that ASPX is converting my tags in a way thats messing them up _before_ it processes the DataBinder.Eval...

Im using C# for my code behind, but not sure if that matters.

Anyone have any ideas?

Paul
 
Last edited by a moderator:
Hi Paul,

i thought, in a Repeater you cant place <ASP:xxxxxx></ASP:xxxxxx> tags - Im I wrong?

I think they will not be rendered! Have you looked after displaying the page in a WebBrowser the generated HTML-Source of this page. I think, the servertags will be unchanged, that means that your HTML-Source contains <ASP:xxxx>

In fact this reply has nothing to do with your question, but when the <ASP:xxxxx> servertags will not be rendert (what i think) you dont have to supreme about your problem...

Try following:

Code:
<asp:Repeater id="Repeater2" runat="server">
<ItemTemplate>
<asp:TextBox ID="tbInsideRepeater"></asp:TextBox>
</ItemTemplate>
</asp:Repeater>

When your HTMLPages source contains <asp:TextBox ID="tbInsideRepeater"></asp:TextBox> you know, it will not be rendered...

Regards, Stefan
 
Actually, you can put <asp:xxx> tags inside a repeater. Thats not the problem. Im well aware of how to view source to see what kind of carnage-they-call-HTML ASP.Net is rendering.

In the interface Im developing I have two repeaters and each has <asp:xxx> tags and html tags with runat=server (and all declared in my code behind) - Im populating the controls with data from a database and saving it just fine from the repeater - thats not a problem. (The repeater will render them based on thier ID - when rendered they get nice ridiculous names like repRepeaterName:_ctl0_controlname which has given me some fun stuff to figure out for using JavaScript with repeater contents...but anyways).

If Im using an <asp:xxx> control on a repeater, I can usually get away with doing this, say Im giving a default value to an <asp:textbox> control, I can give it a VALUE attribute:

value=<%# DataBinder.Eval(Container, "DataItem.SomeDataProperty")%>

...and it works fine - I guess because VALUE is a normal HTML attribute and it doesnt have to be parsed and rendered like the <asp:xxx> attributes - Id guess that ASP.Net just renders standard HTML attributes included in thier <asp:xxx> controls as written.

The problem is when I try do a similar thing with a .Net control attribute - that will ultimately have to be parsed and rendered into some HTML equivalent.

If I try to use a similar trick on an <asp:xxx> specific attribute, like the ErrorMessage attribute of an <asp:requiredfieldvalidator> control, which is an attribute that gets parsed and rendered before ultimately being stuck in the resulting HTML page, then my quotes get butchered and/or not properly handled.

The problem Im having is that I want to use validators with repeater items and be able to give robust error messages in my validation summary. To do that I need to be able to include some kind of reference to the offending repeater row in the error message. A generic message isnt going to do much for my users if I have several items in my repeater.

Paul
 
Woohoo!

Disregard or delete this thread as I figured out how to do it, finally, after searching for days.

I found out how to populate a repeater from the code-behind (which was something else I wanted to know how to do) and using that knowledge was able to set the ErrorMessage property of my validator directly in code and avoid the rendering issues entirely.

To see how to populate a repeater from code-behind (C# example) view this:

http://www.gotdotnet.com/Community/MessageBoard/Thread.aspx?id=10135&Page=1#10135

The line in particular that sets the ErrorMessage for the RequiredFieldValidator looks like:

((RequiredFieldValidator) e.Item.FindControl("validatorcontrolname")).ErrorMessage = oElement.NameField + " " + e.Item.ItemIndex + " is a required field.";

Cheers,
Paul
 
Back
Top