473,320 Members | 2,145 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Creating controls on the fly

I want to create controls on fly. Specifically, I want to create some
ASP.Net Link Buttons dynamically. They would also need click events written
on the fly also. I'm pretty sure you can create controls on the fly but not
sure about events. Does anyone know? Anyone have any examples?
Jul 21 '05 #1
5 1423
Clearricic

This is an old however from the Google Newsgroup disapeared sample from me.

I have resent it recently in this message.

It is a kind of calendar where buttons are created on the fly

http://groups-beta.google.com/group/...07ea54b0?hl=en

I hope this helps,

Cor
Jul 21 '05 #2
This appears to be what I'm looking for. That's a bunch!!!!

"Cor Ligthert" wrote:
Clearricic

This is an old however from the Google Newsgroup disapeared sample from me.

I have resent it recently in this message.

It is a kind of calendar where buttons are created on the fly

http://groups-beta.google.com/group/...07ea54b0?hl=en

I hope this helps,

Cor

Jul 21 '05 #3
Cor,

I notice the "Adding EventHandlers example" works as you posted it but when
I put the code to dynamically create the control on a button click, the event
handler doesn't execute when I click it. Do you know why?

For example:

Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load

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
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
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
"Cor Ligthert" wrote:
Clearricic

This is an old however from the Google Newsgroup disapeared sample from me.

I have resent it recently in this message.

It is a kind of calendar where buttons are created on the fly

http://groups-beta.google.com/group/...07ea54b0?hl=en

I hope this helps,

Cor

Jul 21 '05 #4
Clear-RCIC,

There is nothing in the ASPX page (let say the template) and it is therefore
by every visit build new. What you want can you do by instance like this.

\\\\
Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
If CBool(Session.Item("set")) Then
Button1_Click(Nothing, Nothing)
End If
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
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim mybutton As Button
Dim i As Integer
For i = 0 To New Date().DaysInMonth _
(New Date().Year, New Date().Month) - 1
Session.Item("set") = True
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
Button1.Visible = False
End Sub
///
I hope this helps,

Cor
Jul 21 '05 #5
Thanks. That seems to work but I don't understand why. It looks like you
are setting a boolean with :
Session.Item("set")

But I don't see what calling the button and passing "Nothing" does:
Button1_Click(Nothing, Nothing)

"Cor Ligthert" wrote:
Clear-RCIC,

There is nothing in the ASPX page (let say the template) and it is therefore
by every visit build new. What you want can you do by instance like this.

\\\\
Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
If CBool(Session.Item("set")) Then
Button1_Click(Nothing, Nothing)
End If
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
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim mybutton As Button
Dim i As Integer
For i = 0 To New Date().DaysInMonth _
(New Date().Year, New Date().Month) - 1
Session.Item("set") = True
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
Button1.Visible = False
End Sub
///
I hope this helps,

Cor

Jul 21 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Altramagnus | last post by:
I have 30 - 40 type of different window. For each type I need about 20 instances of the window. When I try to create them, I get "Error creating window handle" My guess is there is a maximum...
0
by: Jai | last post by:
Dear All Creating Custom Controls but Not User Controls,How to create custom controls,i.e Extending the functionality of the Existing Controls.(Web Custom Controls). Previously i have...
3
by: Ken Varn | last post by:
I am just starting the process of creating ASP.NET server controls. I have created controls for .NET applications, but have just started with ASP.NET. I am a little confused about some areas that...
2
by: Patrick | last post by:
I want to define a set of web-form templates in XML and render the equivalent web-form with ASP.NET, then process any input server controls on the form. Reading the XML file from Page_load is...
12
by: Mats Lycken | last post by:
Hi, I'm creating a CMS that I would like to be plug-in based with different plugins handling different kinds of content. What I really want is to be able to load/unload plugins on the fly without...
7
by: Varangian | last post by:
Hello is creating controls at runtime the same as designtime ? will a page be faster if controls are created at designtime rather than at runtime ? If so why ? thanks :)
5
by: SalamElias | last post by:
I am creating several chkBoxes dynamically and assigning an event handler in the Page_load as foillows ***************************** Dim chkCatOption As CheckBox = New CheckBox chkCatOption.Text...
9
by: Tarscher | last post by:
hi all, I have this seemingly simple problem. I have lost a lot of time on it though. When a user selects a value from a dropdownlist (static control) a dynamic control is generated. I have...
1
by: Abdo Haji-Ali | last post by:
Previously I used to create user controls if I wanted to use a specific set of controls in multiple pages, however I want to deploy my control in other applications so I thought of creating custom...
4
by: mohaaron | last post by:
I can think of a lot of reasons why this might need to be done but as far as I can tell it's not possible. I've been looking for a way to add HtmlTableRows to a table using a button click for a...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.