Re: Create dynamically LinkButton controls and EventHandlers
- From: "Kiyomi" <k.kanaoka@xxxxxxxxxx>
- Date: Mon, 10 Oct 2005 13:34:47 +0200
Thank you very much, Carsten, for your advice. Could I ask you some more
questions ?
I have got "Object reference not set to an instance of an object." at the
line :
dynamicDIV.Controls.Add(Table1)
Is this because my Table1 is not really HTMLTable but is an object whose
runat attribute set to Server ? In fact, I created my table on design page
only for its title lines as I need to use column spans and row spans for the
title lines. The body of the table is generated dynamically in the code
behind.
Also, I have several LinkButtons to insert in my Table and the total number
of instances depends on the query results (can be more than hundred). How
can I define the ID for the each instance and deal with them in the
following Select Case when I have hundred IDs ?
Select Case CType(sender, LinkButton).ID
Case "DynamicLinkButton1"
Response.Redirect("PageName")
End Select
I appreciate very much your kind help,
KK
"CT" <carstent@xxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:#QH6fRXzFHA.1264@xxxxxxxxxxxxxxxxxxxxxxx
> Hi KK,
>
> Okay, first you need to make sure that the form has the runat attribute
set
> to Server, which is the default. Then you need a placeholder, such as a
DIV,
> to which you can add the controls. The runat attribute of the placeholder
> must also be set to Server. Then, the following code will work for you:
>
> Protected Sub LinkButton_Click(ByVal sender As Object, ByVal e As
> System.EventArgs)
> Select Case CType(sender, LinkButton).ID
> Case "DynamicLinkButton1"
> Response.Redirect("PageName")
> End Select
> End Sub
>
> Protected Sub Page_Load(ByVal sender As Object, ByVal e As
> System.EventArgs) Handles Me.Load
> ' Instantiate LinkButton
> Dim DynamicLinkButton1 As New LinkButton
> ' Set properties
> DynamicLinkButton1.Text = "Dynamic LinkButton"
> ' Assign an ID you can use to filter in click event
> DynamicLinkButton1.ID = "DynamicLinkButton1"
> ' Add event handler
> AddHandler DynamicLinkButton1.Click, AddressOf LinkButton_Click
>
> ' Instantiate HTML Table
> Dim Table1 As New HtmlTable
> ' Instantiate HTML Table Row
> Dim Row1 As New HtmlTableRow
> ' Instantiate HTML Table Cell
> Dim Cell1 As New HtmlTableCell
> ' Add controls to Table
> Cell1.Controls.Add(DynamicLinkButton1)
> Row1.Controls.Add(Cell1)
> Table1.Controls.Add(Row1)
>
> ' Get place holder on Web form, in this case a DIV
> Dim dynamicDIV As HtmlControl =
CType(Me.FindControl("DynamicDIV"),
> HtmlControl)
> ' Add Table1, including any controls and content
> dynamicDIV.Controls.Add(Table1)
> End Sub
>
> Now, you state that you want to pass a value to the page you're
redirecting
> to. Since this is a new page, you can' use the viewstate, but you can add
a
> value to current session, using Session.Add. Then in the page that you're
> redirecting to, you can access the value using Session.Item. Well, that's
> one way, if you want to avoid the querystring.
>
> --
> Carsten Thomsen
> Communities - http://community.integratedsolutions.dk
>
> "Kiyomi" <k.kanaoka@xxxxxxxxxx> wrote in message
> news:%23hxYFL$yFHA.2424@xxxxxxxxxxxxxxxxxxxxxxx
> > Hello,
> >
> >
> >
> > I create a Table1 dynamically at run time, and at the same time, I would
> > like to create LinkButton controls, also dynamically, and insert them
into
> > each line in my Table1. I would then like that, when clicking the
> > LinkButton, the user can be navigated to another page, carrying a
> > variable.
> > I would like to use server.transfer method instead of QueryString as I
> > don't
> > want the carried variable to be visible for the user.
> >
> >
> >
> > How can I create dynamically LinkButton controls as well as
EventHandlers?
> >
> >
> >
> > Thank you very much for your kind advice,
> >
> >
> >
> > KK
> >
> >
>
>
.
- References:
- Prev by Date: Re: Drag & Drop tab controls in 2005?
- Next by Date: Deployment of Microsoft Office Xp Primary Interop Assembly
- Previous by thread: Re: Create dynamically LinkButton controls and EventHandlers
- Next by thread: Re: UserControl
- Index(es):