Adam
Adam

Reputation: 1242

change asp.net panel rendered tag from div to span

I have an <asp:Panel> inside an li, so the problem is the html will not validate.

Any help in changing the rendered div to a span?

I'm doing this in a ASP.NET 4.0 website using c# code.

Upvotes: 2

Views: 12287

Answers (5)

patmortech
patmortech

Reputation: 10219

It IS possible to change the rendering of a Panel from a div to a span: you could create a Control Adapter that would override the default rendering of the Panel. You can read up on them and see some examples here and here.

However, I think I'd find another option for solving your problem. Changing the behavior of a standard control like this might make it difficult for future developers to understand what's going on in your app. And the effort to get this working may be more than just using one of the other solutions! I can only see this as reasonable if you have a lot of pages with Panels already on them and you are unable/unwilling to change them all to some other mechanism.

Upvotes: 2

Mohsen
Mohsen

Reputation: 65785

if you want to change the tag for styling just add display:inline to your div. It would act as an span

Upvotes: 1

Oleks
Oleks

Reputation: 32333

Take a look onto the Eilon Lipton's article Customizing the rendering of the UpdatePanel.

He shows how to extend update panel with css class and custom tag properties in it.

Upvotes: 1

PHeiberg
PHeiberg

Reputation: 29811

Add javascript in order to enforce your default button behaviour for the contents of the panel and replace the panel with a plain <span> element.

If you are using jQuery, there are a couple of examples available here (check the comments as well).

Upvotes: 1

Brian Mains
Brian Mains

Reputation: 50728

Use a Label control; this equates to a span. You cannot change what the panel renders as.

Upvotes: 5

Related Questions