473,406 Members | 2,705 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,406 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 1428
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.