开发者

change asp.net panel rendered tag from div to span

开发者 https://www.devze.com 2023-02-09 22:48 出处:网络
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 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 开发者_如何学Python4.0 website using c# code.


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


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.


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.


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).


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

0

精彩评论

暂无评论...
验证码 换一张
取 消