Creating linkbutton at runtime with code

  • Thread starter Thread starter Jason
  • Start date Start date
J

Jason

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
 
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()
 
* "CJ Taylor said:
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?
 
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/d...l/vbtskcodeexampleaddingcontrolsatruntime.asp


I hope this helps a little bit?

Cor
 
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. =)
 
* "CJ Taylor said:
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.
 
Back
Top