Watch this video on user controls
https://www.youtube.com/watch?v=iLDx8G8Qgb0[
^]
What your doing in your example is old school, sort of asp classic or php like.
In asp.net, you can create a server control in code behind of html elements, or a user control, and just register the control using the <% %> and place the control in your desired location.
This is just a fast cut and paste example of how it works in VB, you can code in C# if you like, this example will not run. But the server control code is the basic format to start with, or you can go to solution explorer and load a template.
You build you control first, just the basics, a container with a border so you can see it first.
So you have a webform, you register the control and place the code in a container
and run the form to make sure you can see the control.
Then you start building out your control.
In the RenderDesignMode, you can build a preview of your control for use in the Visual Studio Design View. Keep in mind that in the RenderDesign, All your doing is creating something that represents the concept of the control, and allow you to edit the properties of the control using F4
The OnInit is for creating HTML Elements that persist on postback to the server
The OnLoad is for populate the elements, you can create HTML there to as well, but they won't persist on postback, you have to create them every time the page loads.
<![CDATA[<%@ Page Language="VB" MasterPageFile="~/masterpages/HomePage.master" ...
<%@ Register Assembly="redCopper.FlashObject_Net40" Namespace="FlashObject" TagPrefix="movie" %>]]>
<body>
<asp:content id="UpperContent" runat="Server" contentplaceholderid="UpperContent" mode="hold" xmlns:asp="#unknown" /> <div style="text-align: center; width: 960px; margin: 0px auto;">
<div style="width: 758px; height: 400px;">
<movie:flash_swfObject_2
ID="T758x400"
runat="server"
Alignment="Center"
AllowScriptAccess="samedomain"
Flash_AutoPlay="True"
Flash_BGColor="rgb(0,0,0)"
Flash_ExpressInstall_Url="~/Flash/expressInstall.swf"
Flash_MovieID="T758x400"
Flash_MovieUrl="~/Flash/Jazz_Loader.swf"
Flash_MovieUrl_Alt="~/Flash/Jazz_Loader.swf"
Flash_Quality="AutoHigh"
Flash_wMode="Transparent"
Flash_ZIndex="900"
Flash_LoopMovie="true"
Style="top: 0px; left: -1px"
Height="400px"
Width="758px"
DisplayAdvertisingFilmstrip_Specified="True"
DisplayAdvertisingFilmstrip_Url="~/Flash/Jazz_Collection_NonFlash.html" />
</body>
And then you build your control
<DefaultProperty("Text"), ToolboxData("<{0}:FlashObject runat=server></{0}:FlashObject>")> _
Public Class flash_html_Object
Inherits WebControl
Private div_SWF_Container As Panel
Private hl_TrialLink As HyperLink
Public lit_AC_RunActiveContent As LiteralControl
Public lit_FlashObject As LiteralControl
Protected Overrides Sub Render(ByVal writer As HtmlTextWriter)
If Not HttpContext.Current Is Nothing Then
RenderContents(writer)
Else
RenderDesignMode(writer)
RenderContents(writer)
End If
End Sub
Protected Overrides Sub OnInit(ByVal e As System.EventArgs)
MyBase.OnInit(e)
Controls.Clear()
Dim panel_SWF_Container As Panel
panel_SWF_Container = New Panel
With panel_SWF_Container
.ID = [ID] & "_panel_SWF_Container"
.Style.Add(HtmlTextWriterStyle.Width, [Width].Value.ToString & "px")
.Style.Add(HtmlTextWriterStyle.ZIndex, [Flash_ZIndex])
.Style.Add(HtmlTextWriterStyle.Position, "relative")
.Style.Add(HtmlTextWriterStyle.TextAlign, e_Movie_Alignment)
.Style.Add(HtmlTextWriterStyle.Margin, "0px auto")
.Style.Add(HtmlTextWriterStyle.Display, "Block")
End With
Controls.Add(panel_SWF_Container)
div_SWF_Container = New Panel
With div_SWF_Container
.Style.Add(HtmlTextWriterStyle.Height, [Height].ToString)
.Style.Add(HtmlTextWriterStyle.Width, [Width].ToString)
.Style.Add(HtmlTextWriterStyle.TextAlign, e_Movie_Alignment)
End With
panel_SWF_Container.Controls.Add(div_SWF_Container)
End Sub
Private Sub RenderDesignMode(ByVal writer As HtmlTextWriter)
Controls.Clear()
End Sub
Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
MyBase.OnLoad(e)
If Not Page.IsPostBack Then
End If
End Sub
<Bindable(True)> _
<Category("Appearance")> _
<DefaultValue("(none)")> _
<Localizable(True)> _
Public Property Text() As String
Get
Dim _Text As String = CStr(ViewState("Text"))
If _Text Is Nothing Then
Return String.Empty
Else
Return _Text
End If
End Get
Set(ByVal Value As String)
ViewState("Text") = Value
End Set
End Property