473,480 Members | 2,349 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Creating linkbutton at runtime with code

Hi everyone,

Have a small problem which I hope you can help me with.

I'm trying to create several link buttons at runtime which
run a routine when clicked.

I've tried to create a VERY basic example before I carry
on, but even this isn't working.

My code is...

Dim lnkName As New LinkButton()
lnkName.Text = "HitTest"
lnkName.CommandName = "test"
lnkName.CommandArgument = "1"
lnkName.ID = "HitTest"

Dim tc As New HtmlTableCell()
Dim tr As New HtmlTableRow()
tc.InnerText = "JJ"
tc.Controls.Add(lnkName)
tr.Cells.Add(tc)
tblToResults.Rows.Add(tr)

tblToResults.Style.Item("DISPLAY") = "Block"

Return False
End Function

Sub test(ByVal d)
Response.Redirect("kkkk")
End Sub
TIA
Nov 20 '05 #1
8 4169
Before your code starts creating the controls

call
me.SuspendLayout()

then, you have to add your new control to the other control... i.e

me.Controls.Add(myControl)

me.ResumeLayout()
"Jason" <an*******@discussions.microsoft.com> wrote in message
news:0e****************************@phx.gbl...
Hi everyone,

Have a small problem which I hope you can help me with.

I'm trying to create several link buttons at runtime which
run a routine when clicked.

I've tried to create a VERY basic example before I carry
on, but even this isn't working.

My code is...

Dim lnkName As New LinkButton()
lnkName.Text = "HitTest"
lnkName.CommandName = "test"
lnkName.CommandArgument = "1"
lnkName.ID = "HitTest"

Dim tc As New HtmlTableCell()
Dim tr As New HtmlTableRow()
tc.InnerText = "JJ"
tc.Controls.Add(lnkName)
tr.Cells.Add(tc)
tblToResults.Rows.Add(tr)

tblToResults.Style.Item("DISPLAY") = "Block"

Return False
End Function

Sub test(ByVal d)
Response.Redirect("kkkk")
End Sub
TIA

Nov 20 '05 #2
* "CJ Taylor" <no****@blowgoats.com> scripsit:
Before your code starts creating the controls

call
me.SuspendLayout()

then, you have to add your new control to the other control... i.e

me.Controls.Add(myControl)

me.ResumeLayout()


Mhm... Isn't the OP talking about web forms?

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #3
Cor
Hi Jason,

Did I suply you this code before

It is a calender I made once as an example, of course you can better use the
calandercontrol for that, but as example with buttons it is fine

\\\ It needs to drag a panel on a page
Private mybutton(31) As Button
Private mylabel As New Label
Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim i As Integer
For i = 0 To System.DateTime.DaysInMonth(2003, 11) - 1
mybutton(i) = New Button
mybutton(i).BackColor = Drawing.Color.AntiqueWhite
mybutton(i).Text = (i + 1).ToString
mybutton(i).Width = New Unit(30)
Me.panel1.Controls.Add(mybutton(i))
AddHandler mybutton(i).Click, AddressOf mybutton_Click
If (i + 1) Mod 5 = 0 Then
Me.panel1.Controls.Add(New LiteralControl("<BR>"))
End If
Next
Me.panel1.Controls.Add(New LiteralControl("<BR><BR>"))
Me.panel1.Controls.Add(mylabel)
End Sub
Private Sub mybutton_Click _
(ByVal sender As Object, ByVal e As System.EventArgs)
Dim day As Button = DirectCast(sender, Button)
mylabel.Text = "The day is: " & day.Text
End Sub
///
http://msdn.microsoft.com/library/de...satruntime.asp
I hope this helps a little bit?

Cor
Nov 20 '05 #4
what?

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:bq*************@ID-208219.news.uni-berlin.de...
* "CJ Taylor" <no****@blowgoats.com> scripsit:
Before your code starts creating the controls

call
me.SuspendLayout()

then, you have to add your new control to the other control... i.e

me.Controls.Add(myControl)

me.ResumeLayout()


Mhm... Isn't the OP talking about web forms?

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>

Nov 20 '05 #5
* "CJ Taylor" <no****@blowgoats.com> scripsit:
what?


I didn't know that 'SuspendLayout' and 'ResumeLayout' work in web
forms...

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #6
Oh... they dont. I thought we were talking about win forms in this example.
:) Usually, when anyone brings up ASP.NET in here, your the first one to
push them to the asp.net group...

So I simply ASSumed, that this was winforms. =).. In either sense, the code
that was given, they still didn't add the code to a control container. =)

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:bq*************@ID-208219.news.uni-berlin.de...
* "CJ Taylor" <no****@blowgoats.com> scripsit:
what?


I didn't know that 'SuspendLayout' and 'ResumeLayout' work in web
forms...

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>

Nov 20 '05 #7
* "CJ Taylor" <no****@blowgoats.com> scripsit:
Oh... they dont. I thought we were talking about win forms in this example.
:) Usually, when anyone brings up ASP.NET in here, your the first one to
push them to the asp.net group...

So I simply ASSumed, that this was winforms. =).. In either sense, the code
that was given, they still didn't add the code to a control container. =)


;-)

I was not sure if it was related to Windows Forms, that's why I didn't
reply to the OP's post.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #8
Many thanks

-----Original Message-----
Hi Jason,

Did I suply you this code before

It is a calender I made once as an example, of course you can better use thecalandercontrol for that, but as example with buttons it is fine
\\\ It needs to drag a panel on a page
Private mybutton(31) As Button
Private mylabel As New Label
Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim i As Integer
For i = 0 To System.DateTime.DaysInMonth(2003, 11) - 1
mybutton(i) = New Button
mybutton(i).BackColor = Drawing.Color.AntiqueWhite
mybutton(i).Text = (i + 1).ToString
mybutton(i).Width = New Unit(30)
Me.panel1.Controls.Add(mybutton(i))
AddHandler mybutton(i).Click, AddressOf mybutton_Click
If (i + 1) Mod 5 = 0 Then
Me.panel1.Controls.Add(New LiteralControl("<BR>"))
End If
Next
Me.panel1.Controls.Add(New LiteralControl("<BR><BR>"))
Me.panel1.Controls.Add(mylabel)
End Sub
Private Sub mybutton_Click _
(ByVal sender As Object, ByVal e As System.EventArgs)
Dim day As Button = DirectCast(sender, Button)
mylabel.Text = "The day is: " & day.Text
End Sub
///
http://msdn.microsoft.com/library/default.asp? url=/library/en-
us/dv_vbcode/html/vbtskcodeexampleaddingcontrolsatruntime.a
sp

I hope this helps a little bit?

Cor
.

Nov 20 '05 #9

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

Similar topics

0
296
by: Mike P | last post by:
Can anybody tell me what is wrong with this code? The main error I seem to be getting is where I am creating the LinkButton called deleteButton. public void dgLog_ItemDataBound(object sender,...
3
1452
by: simon | last post by:
Hello, i'm looking to create an aspx page that is basically a FAQ page i'm not sure if this can be done, but would love some help with suggestions of how to do it another way if this is not...
7
5253
by: Alex Maghen | last post by:
I have a DataGrid control with a LinkButton command column that deletes the row. What I want to do is set it up so that there's a client-side Confirm alert BEFORE the actual Delete command gets...
0
1309
by: JSanford9482 | last post by:
Hi All, I have a Repeater that contains a LinkButton as one of the items in the ItemTemplate. I have the OnCommand (method is called "messageActions") and CommandName ("view") properties set, as...
5
4692
by: =?Utf-8?B?TWFyYyBXb29sZnNvbg==?= | last post by:
Hi, I have a strange issue occurring with LinkButtons that are dynamically added to each (data) row of my DataGrid on that grid's ItemDataBound event. Each LinkButton is assigned its own event...
5
2288
by: tshad | last post by:
I found I can create Template columns dynamically - as long as I don't use objects that need onclick events, such as a LinkButton. Textboxes and Labels work fine. I create the Template columns...
0
1354
by: Syoam4ka | last post by:
My project is about jewellery. I have devided my jewelery into main types, which each one of them has sub types, and each one those sub types has the jewellery. I have a tabcontainer. It includes...
2
1902
by: Mufasa | last post by:
I have code to dynamically generate some link buttons (It's not know how many are needed until runtime.) I am adding the linkbutton to a cell in a table and the adding works fine. It's firing of...
5
13890
by: Peter Larsen [CPH] | last post by:
Hi, The following sample shows a LinkButton in the HeaderTemplate of a Repeater control. The problem is that i'm not able to access the linkbutton in code (in the cs file) as long as the...
0
7048
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7050
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7091
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...
1
6743
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...
1
4787
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...
0
2999
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
2988
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
564
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
185
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.