Click here to Skip to main content
15,887,683 members
Home / Discussions / ASP.NET
   

ASP.NET

 
QuestionHow can Access a Div without add runar="server" in code behind? Pin
anoop_m8324-May-10 12:58
anoop_m8324-May-10 12:58 
AnswerRe: How can Access a Div without add runar="server" in code behind? Pin
Not Active24-May-10 13:35
mentorNot Active24-May-10 13:35 
GeneralRe: How can Access a Div without add runar="server" in code behind? Pin
anoop_m8324-May-10 13:46
anoop_m8324-May-10 13:46 
GeneralRe: How can Access a Div without add runar="server" in code behind? Pin
Not Active24-May-10 14:17
mentorNot Active24-May-10 14:17 
GeneralRe: How can Access a Div without add runar="server" in code behind? Pin
anoop_m8324-May-10 14:33
anoop_m8324-May-10 14:33 
AnswerRe: How can Access a Div without add runar="server" in code behind? Pin
doudoufly2-Jun-10 0:05
doudoufly2-Jun-10 0:05 
QuestionExample ASP.NET training project, which uses a database, users can enter under the login and apply the session. Pin
vn2145624-May-10 10:50
vn2145624-May-10 10:50 
QuestionDynamic Content + Reflection + Server Controls Pin
CP_Klewis24-May-10 10:25
CP_Klewis24-May-10 10:25 
Hello,

I have created many user controls with custom properties, methods, etc. to help interact between my business layer and presentation layer. I have also developed a custom page class that is derived from the base Page class. Everything works well if I create my aspx pages statically and by this I mean insert the markup directly into the aspx pages source.

I had an idea to try and make my application more user friendly and have my pages source come from xml files defined by the end user. Since all of my custom server controls are in a single assembly, I figured I could use reflection to create the controls and insert them into the page. I have the code for this written, however, when I add the controls to the page (using reflection), I cannot access the base page class from within my custom controls.

Example.

I have a base page called UIBase dereived from System.Web.UI.Page.

I have a server control that is derived from System.Web.UI.Control. Within my custom control, I have a property that returns the controls page cast as the UIBase (which ALL of my pages within the site are set as via web.config)

public readonly property CtlPage() as UIBase
Get
Return ctype(me.page,UIBase)
End Get
end property


When I use reflection, I get an error within the return statement above. Unable to cast webform3_aspx as UIBase. I can dynamically add the controls via the page_init and add them to the page with no problem. This error only happens when reflection is used....

Also note that the UIBase class is in the same assembly as all other controls. Could this be the problem?

Here is my code that uses reflection to add the controls to the page.

Dim ctlAssem As System.Reflection.Assembly
Dim an As System.Reflection.AssemblyName = New System.Reflection.AssemblyName("MyWeb.Web.UI.Controlls")
an.CodeBase = "MyWeb.Web.UI.Controlls.dll"
ctlAssem = System.Reflection.Assembly.LoadFile("../../MyWeb.Web.UI.Controls.dll") 'shortened for readability

Private Sub initControls()
Dim mst As uibasepage_master = Page.Master

Dim xmlDoc As New XmlDocument()
xmlDoc.Load(Server.MapPath("~/page_source/Employee.xml"))

Dim root As XmlNode = xmlDoc.DocumentElement
createControls(root, mst.BodyContent)

End Sub

Private Sub createControls(ByRef parentNode As XmlNode, ByRef parentCtl As Control)

If parentNode.ChildNodes.Count > 0 Then
For Each childNode As XmlNode In parentNode.ChildNodes
Dim ctlType As Type = ctlAssem.GetType("MyWeb.Web.UI.Controls." & childNode.Name)
Dim ctl As Control = Activator.CreateInstance(ctlType)

For Each ctlAttr As XmlAttribute In childNode.Attributes
Dim pi As System.Reflection.PropertyInfo = ctlType.GetProperty(ctlAttr.Name)
If pi.PropertyType Is GetType(String) Then
pi.SetValue(ctl, ctlAttr.Value, Nothing)
ElseIf pi.PropertyType Is GetType(Boolean) Then
If ctlAttr.Value.ToString.ToLower = "true" Then
pi.SetValue(ctl, True, Nothing)
Else
pi.SetValue(ctl, False, Nothing)
End If
End If



Next

parentCtl.Controls.Add(ctl)
If childNode.HasChildNodes Then
createControls(childNode, ctl)
End If
Next

End If
End Sub


Thanks to anyone that can help. This has drove me nuts for a few days now.
AnswerRe: Dynamic Content + Reflection + Server Controls Pin
T M Gray24-May-10 11:05
T M Gray24-May-10 11:05 
GeneralRe: Dynamic Content + Reflection + Server Controls Pin
CP_Klewis25-May-10 1:27
CP_Klewis25-May-10 1:27 
QuestionWeb Service on https site Pin
#realJSOP24-May-10 9:48
mve#realJSOP24-May-10 9:48 
QuestionGridview containing dependent dropdownlists errors on edit. Pin
janetb9924-May-10 9:09
janetb9924-May-10 9:09 
QuestionHow to get the date value from Date time Pin
Amit Patel198524-May-10 9:00
Amit Patel198524-May-10 9:00 
AnswerRe: How to get the date value from Date time Pin
Not Active24-May-10 9:09
mentorNot Active24-May-10 9:09 
QuestionAjaxControlToolkit AutoCompleteExtender Pin
Crapaw4524-May-10 8:20
Crapaw4524-May-10 8:20 
AnswerRe: AjaxControlToolkit AutoCompleteExtender Pin
T M Gray24-May-10 11:01
T M Gray24-May-10 11:01 
GeneralRe: AjaxControlToolkit AutoCompleteExtender Pin
Crapaw4524-May-10 11:05
Crapaw4524-May-10 11:05 
GeneralRe: AjaxControlToolkit AutoCompleteExtender Pin
T M Gray24-May-10 11:22
T M Gray24-May-10 11:22 
GeneralRe: AjaxControlToolkit AutoCompleteExtender Pin
Crapaw4525-May-10 4:56
Crapaw4525-May-10 4:56 
QuestionWhere are maxWorkerThreads and maxIoThreads in .NET 2.0? Pin
Xiangyang Liu 刘向阳24-May-10 7:25
Xiangyang Liu 刘向阳24-May-10 7:25 
Questionwant one sql query... Pin
hi_everybody24-May-10 7:18
hi_everybody24-May-10 7:18 
AnswerRe: want one sql query... Pin
Brij24-May-10 8:22
mentorBrij24-May-10 8:22 
GeneralRe: want one sql query... Pin
hi_everybody26-May-10 7:59
hi_everybody26-May-10 7:59 
AnswerRe: want one sql query... Pin
Crapaw4524-May-10 8:43
Crapaw4524-May-10 8:43 
GeneralRe: want one sql query... Pin
hi_everybody26-May-10 8:01
hi_everybody26-May-10 8:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.