Answered by:
converting user control to server control...

Question
-
User-951615850 posted
Hello,
I have created a templated user control and i would like to convert it into server control. Could anyone help me achive this?
This is sample of my user control.
Thanks..
<%@ Control Language="vb" AutoEventWireup="false" CodeBehind="VendorPopup.ascx.vb" Inherits="ParentsChoiceWebApplication.VendorPopup" %> <table width="750px" class="popup" border="0" cellspacing="0" cellpadding="0"> <thead> <tr> <td> <asp:PlaceHolder ID="Header" runat="server"></asp:PlaceHolder> </td> </tr> </thead> <tbody> <tr> <td> <asp:PlaceHolder ID="Body" runat="server"></asp:PlaceHolder> </td> </tr> </tbody> <tfoot> <tr> <td> <asp:PlaceHolder ID="Footer" runat="server"></asp:PlaceHolder> </td> </tr> </tfoot> </table>
Imports System.ComponentModel Imports System.Web.UI Imports System.Web.UI.WebControls <ParseChildren(True)> _ Partial Public Class VendorPopup Inherits System.Web.UI.UserControl Private _text As String Private _headerTemplate As ITemplate Private _bodyTemplate As ITemplate Private _footerTemplate As ITemplate <PersistenceMode(PersistenceMode.InnerProperty), TemplateContainer(GetType(TemplateControl))> _ Public Property HeaderTemplate() As ITemplate Get Return _headerTemplate End Get Set(ByVal value As ITemplate) _headerTemplate = value End Set End Property <PersistenceMode(PersistenceMode.InnerProperty), TemplateContainer(GetType(TemplateControl))> _ Public Property BodyTemplate() As ITemplate Get Return _bodyTemplate End Get Set(ByVal value As ITemplate) _bodyTemplate = value End Set End Property <PersistenceMode(PersistenceMode.InnerProperty), TemplateContainer(GetType(TemplateControl))> _ Public Property FooterTemplate() As ITemplate Get Return _footerTemplate End Get Set(ByVal value As ITemplate) _footerTemplate = value End Set End Property <Bindable(True), DefaultValue("")> Public Property Text() As String Get Return _text End Get Set(ByVal value As String) _text = value End Set End Property Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load End Sub Protected Overrides Sub OnInit(ByVal e As EventArgs) MyBase.OnInit(e) If _headerTemplate IsNot Nothing Then _headerTemplate.InstantiateIn(Header) End If If _bodyTemplate IsNot Nothing Then _bodyTemplate.InstantiateIn(Body) End If If _footerTemplate IsNot Nothing Then _footerTemplate.InstantiateIn(Footer) End If End Sub End Class
Tuesday, December 29, 2009 10:00 PM
Answers
-
User-1550750733 posted
You can't really do this easily the main reason is that they are two different classes i.e. System.Web.UI.UserControl and System.Web.UI.WebControl.
You would need to create a vb class that inherits System.Web.UI.WebControl
then override the method CreateChildControls and add you controls that you have done on the ascx file then do the other overrides you have i.e. OnInit compile and add a reference to you tool box then drag and drop in to the page/control you desire.
More info check out
http://msdn.microsoft.com/en-us/library/yhzc935f(VS.80).aspx
for a good walk through guide
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, December 29, 2009 10:25 PM -
User-16411453 posted
The post above is right, it not really a conversion thing,
You have to sit down and say I'm going to write a server control, and learn how to do it. It's not like xml where the focus is really small, cause it's just a xml file. The scope of a server control can go really broad in it's architecture.
If you have trouble along the way, you can ask for help.
Try creating your webform code in code behind, or pure code first, and then take the next step in creating a server control.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Sunday, January 3, 2010 12:50 AM
All replies
-
User-1550750733 posted
You can't really do this easily the main reason is that they are two different classes i.e. System.Web.UI.UserControl and System.Web.UI.WebControl.
You would need to create a vb class that inherits System.Web.UI.WebControl
then override the method CreateChildControls and add you controls that you have done on the ascx file then do the other overrides you have i.e. OnInit compile and add a reference to you tool box then drag and drop in to the page/control you desire.
More info check out
http://msdn.microsoft.com/en-us/library/yhzc935f(VS.80).aspx
for a good walk through guide
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, December 29, 2009 10:25 PM -
User-16411453 posted
The post above is right, it not really a conversion thing,
You have to sit down and say I'm going to write a server control, and learn how to do it. It's not like xml where the focus is really small, cause it's just a xml file. The scope of a server control can go really broad in it's architecture.
If you have trouble along the way, you can ask for help.
Try creating your webform code in code behind, or pure code first, and then take the next step in creating a server control.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Sunday, January 3, 2010 12:50 AM