Any idea for Creating controls according to configuration?

  • Thread starter Thread starter Rhett
  • Start date Start date
R

Rhett

Hello,guys!

I need some idea for Creating controls accoring to configuration.

The context.

Some controls are configured by xml, and there's also some xml string
to configure the layout of all the layout.It could be simple,just a
html table,and make it possible to layout controls by a table grid.

But a more wonderful one is expected to be possible:configure the
layout with plain html including images,links,div and so on,and the
controls are just laid in it by id.
I'm not sure how to implement it.Maybe the layout configure could be a
ascx-content like,then the code could loadTemplate dynamic,but how to
replace or add the controls?Of course, a step by step,element by
element parsing solution could be more adaptable,that surely has lots
of tag to manage.

I'd like hear you ideas,thanks!

btw,is it possible to loadTemplate dynamicly from string,but not from
virtualPath? thanks!
 
Rhet,

I assume it is a webform

See this sample I made (and changed a little bit today)

\\\Needs a panel on the page where the name panel is deleted
Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim mybutton As Button
Dim i As Integer
For i = 0 To New Date().DaysInMonth _
(New Date().Year, New Date().Month) - 1
mybutton = New Button
mybutton.BackColor = Drawing.Color.White
mybutton.Text = (i + 1).ToString
mybutton.Width = New Unit(30)
Me.Panel1.Controls.Add(mybutton)
AddHandler mybutton.Click, AddressOf mybutton_Click
If (i + 1) Mod 5 = 0 Then
Me.Panel1.Controls.Add(New LiteralControl("<BR>"))
End If
Next
End Sub
Private Sub mybutton_Click _
(ByVal sender As Object, ByVal e As System.EventArgs)
Dim mylabel As New Label
Me.Panel1.Controls.Add(New LiteralControl("<BR><BR>"))
Me.Panel1.Controls.Add(mylabel)
mylabel.Text = "The day is: " & DirectCast(sender, Button).Text
End Sub
////

Link
http://msdn.microsoft.com/library/d...l/vbtskcodeexampleaddingcontrolsatruntime.asp

I hope this helps a little bit?

Cor
 
Hello Cor!

You may miss my point.

the most important is the layout,just think about a html table
organizing all the controls specified in controls config, but also
including other elements,like images, links that scriptted in the
layout config
 
Rhet,
You may miss my point.

the most important is the layout,just think about a html table
organizing all the controls specified in controls config, but also
including other elements,like images, links that scriptted in the
layout config

Did you look at the sample?

Have a look in the sample at
Me.Panel1.Controls.Add(New LiteralControl("<BR>"))

Cor
 
I mean the layout is configured like below

<table>
<tr>
<td controlid='ctrl1'></td><td controlid='ctrl2'></td>
</tr>
<tr>
<td colspan='2'><img src='img1.gif'></img></td>
</tr>
</table>


all the layout is configured like above, more elements like '<div>'
'<a>',which will render much wonderful UI.
The important is the layout is configured by script,not by code.
 
Rhett,

I did not try however when it was my problem I would try something as I
showed however now in even more code.

\\\
setLit("<table>")
setLit("<tr>")
etc
///
\\\
Private Sub setLit(byval Lit as string)
Me.Panel1.Controls.Add(New LiteralControl(Lit))
End sub
///

I hope this helps

Copr
 
Back
Top