As far as I know server controls doesn't have a .aspx file. So I need to load a aspx file in order for it to work like a template for my server control, and render my server control content.开发者_如何学Python
How can I do that?
You can create a User Control: like Page
classes, they're paired with templates (that use the ascx
extension rather than aspx
).
If you're obliged to deliver a custom server control instead, you'll need to create your own templating mechanism.
You can dynamically load a usercontrol ASCX into your server control and add it to the Controls collection using the LoadControl method ... not sure if that's exactly what you mean though. Here's an article on doing that, here.
In order to render your server control, you simply need to add the dynamic controls. The framework will do the rest.
In VB:
Dim TB as new LiteralControl("Some custom text here.")
Me.Controls.Add(TB)
If you want to customize the output, override the Render method and make any changes before MyBase.Render is called.
'Me.Controls(0) would be the literal control added above
Me.Controls(0).Text += "Some custom text added at Render."
You can't. Just like you said, server controls do not have .aspx files.
精彩评论