472,978 Members | 2,406 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Dynamically add link button

On code behind file:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then

Dim ctrl As New LinkButton
ctrl.ID = "link1"
ctrl.Text = "link create"
ctrl.CommandArgument = "myargument"
ctrl.CommandName = "mycommandname"
AddHandler ctrl.Click, AddressOf link_button_click
plcCategory.Controls.Add(ctrl)

End If
End Sub

Sub link_button_click(ByVal sender As Object, ByVal e As System.EventArgs)
Response.Write("test")
End Sub

AND page:

<form id="Form1" method="post" runat="server">
<asp:PlaceHolder ID="plcCategory" Runat="server"></asp:PlaceHolder>
</form>

What is wrong here?
I would like to dynamically add more link buttons. Here is example for one
and click event doesn't work.
All link buttons should use link_button_click event.

Thank you,
Simon
Nov 18 '05 #1
8 10739
why dont you just place a label where you want the link and then output the html for the link to it

mylabel.text="<a href=alink.aspx?qry>click here </a>

Nov 18 '05 #2
or to this your way probably need to use the grid control so can use a bubble event to action the click from one of the link button

Nov 18 '05 #3
Hi, Simon

Try add WithEvents in the definition
Dim WithEvents ctrl As New LinkButto

Bin Song, MCP
Nov 18 '05 #4
Hi, Simon,

You should add the control independant on IsPostBack. i.e.:

"simon" <si*********@stud-moderna.si> wrote in message
news:uw*************@tk2msftngp13.phx.gbl...
On code behind file:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
' If Not Page.IsPostBack Then
Dim ctrl As New LinkButton
ctrl.ID = "link1"
ctrl.Text = "link create"
ctrl.CommandArgument = "myargument"
ctrl.CommandName = "mycommandname"
AddHandler ctrl.Click, AddressOf link_button_click
plcCategory.Controls.Add(ctrl)
' End If
End Sub
IMO a more appropriate place to dynamically add controls is the Page_Init
automatic handler or overriding the protected Contsruct method.

Hope this helps
Martin

Sub link_button_click(ByVal sender As Object, ByVal e As System.EventArgs)
Response.Write("test")
End Sub

AND page:

<form id="Form1" method="post" runat="server">
<asp:PlaceHolder ID="plcCategory" Runat="server"></asp:PlaceHolder>
</form>

What is wrong here?
I would like to dynamically add more link buttons. Here is example for one
and click event doesn't work.
All link buttons should use link_button_click event.

Thank you,
Simon


Nov 18 '05 #5
I have dataRepeater and ItemTemplate:

<itemTemplate>
<%# writeLine(0,DataBinder.Eval(Container.DataItem,
"ts_id"),DataBinder.Eval(Container.DataItem, "timeStart"))%>
</itemTemplate>

In write line function I check if there exsists something and if it does, I
would like to add linkButton else something else.
When user clicks this button some pannel will show and so on.

Is there some other way?

Second question.

I have couple lists of codes. When user clicks the button, Iwould like to
show this codes to him in some combo box.
Then he choose one and codes dissapear.

I can do that like combo box on panel and set panel's visibility to
false.When user click the button set visibility to true and when choose the
code set visibility again to false.But that means that every time user want
this page all my lists must be loaded to him.That means slow page. I can do
that dynamically and load this scripts to him only when user click buton or
with javaScript and window.open method.

Is there some other method?

Thank you,
Simon

But dynamically, this won't work

"Martin Dechev" <de*******@hotmail.com> wrote in message
news:%2***************@TK2MSFTNGP09.phx.gbl...
Hi, Simon,

You should add the control independant on IsPostBack. i.e.:

"simon" <si*********@stud-moderna.si> wrote in message
news:uw*************@tk2msftngp13.phx.gbl...
On code behind file:

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


' If Not Page.IsPostBack Then
Dim ctrl As New LinkButton
ctrl.ID = "link1"
ctrl.Text = "link create"
ctrl.CommandArgument = "myargument"
ctrl.CommandName = "mycommandname"
AddHandler ctrl.Click, AddressOf link_button_click
plcCategory.Controls.Add(ctrl)


' End If
End Sub


IMO a more appropriate place to dynamically add controls is the Page_Init
automatic handler or overriding the protected Contsruct method.

Hope this helps
Martin

Sub link_button_click(ByVal sender As Object, ByVal e As System.EventArgs) Response.Write("test")
End Sub

AND page:

<form id="Form1" method="post" runat="server">
<asp:PlaceHolder ID="plcCategory" Runat="server"></asp:PlaceHolder>
</form>

What is wrong here?
I would like to dynamically add more link buttons. Here is example for one and click event doesn't work.
All link buttons should use link_button_click event.

Thank you,
Simon

Nov 18 '05 #6
Hi, Simon,

See inline

"simon" <si*********@stud-moderna.si> wrote in message
news:#v*************@TK2MSFTNGP09.phx.gbl...
I have dataRepeater and ItemTemplate:

<itemTemplate>
<%# writeLine(0,DataBinder.Eval(Container.DataItem,
"ts_id"),DataBinder.Eval(Container.DataItem, "timeStart"))%>
</itemTemplate>

In write line function I check if there exsists something and if it does, I would like to add linkButton else something else.
When user clicks this button some pannel will show and so on.

Is there some other way?
For me it is easier to have the linkbutton and "the other thing" ready. Just
set their visibilities and properties. But maybe in your case it is
something more complex, so if it works this way - fine.
Second question.

I have couple lists of codes. When user clicks the button, Iwould like to
show this codes to him in some combo box.
Then he choose one and codes dissapear.

I can do that like combo box on panel and set panel's visibility to
false.When user click the button set visibility to true and when choose the code set visibility again to false.But that means that every time user want this page all my lists must be loaded to him.
If the panel is Visible = false, it and all its child controls are not
rendered to the client, so there will be no load.

On the button click load the DropDownList with the values and set the panel
Visible=true. Then on the DropDownList SelectedIndexChanged event set it
Visible = false again.

Hope this helps
Martin
That means slow page. I can do
that dynamically and load this scripts to him only when user click buton or with javaScript and window.open method.

Is there some other method?

Thank you,
Simon

But dynamically, this won't work

"Martin Dechev" <de*******@hotmail.com> wrote in message
news:%2***************@TK2MSFTNGP09.phx.gbl...
Hi, Simon,

You should add the control independant on IsPostBack. i.e.:

"simon" <si*********@stud-moderna.si> wrote in message
news:uw*************@tk2msftngp13.phx.gbl...
On code behind file:

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


' If Not Page.IsPostBack Then
Dim ctrl As New LinkButton
ctrl.ID = "link1"
ctrl.Text = "link create"
ctrl.CommandArgument = "myargument"
ctrl.CommandName = "mycommandname"
AddHandler ctrl.Click, AddressOf link_button_click
plcCategory.Controls.Add(ctrl)


' End If
End Sub


IMO a more appropriate place to dynamically add controls is the Page_Init
automatic handler or overriding the protected Contsruct method.

Hope this helps
Martin

Sub link_button_click(ByVal sender As Object, ByVal e As

System.EventArgs) Response.Write("test")
End Sub

AND page:

<form id="Form1" method="post" runat="server">
<asp:PlaceHolder ID="plcCategory" Runat="server"></asp:PlaceHolder> </form>

What is wrong here?
I would like to dynamically add more link buttons. Here is example for one and click event doesn't work.
All link buttons should use link_button_click event.

Thank you,
Simon



Nov 18 '05 #7
Simon,

When you place a control on a page dynamically and that control posts back
you need to re-create the control.

If the control doesn't exist then none of it's event code will fire.

Simply take your link button out of the IsPostBack if/then and your code
will work.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"simon" <si*********@stud-moderna.si> wrote in message
news:uw*************@tk2msftngp13.phx.gbl...
On code behind file:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then

Dim ctrl As New LinkButton
ctrl.ID = "link1"
ctrl.Text = "link create"
ctrl.CommandArgument = "myargument"
ctrl.CommandName = "mycommandname"
AddHandler ctrl.Click, AddressOf link_button_click
plcCategory.Controls.Add(ctrl)

End If
End Sub

Sub link_button_click(ByVal sender As Object, ByVal e As System.EventArgs)
Response.Write("test")
End Sub

AND page:

<form id="Form1" method="post" runat="server">
<asp:PlaceHolder ID="plcCategory" Runat="server"></asp:PlaceHolder>
</form>

What is wrong here?
I would like to dynamically add more link buttons. Here is example for one
and click event doesn't work.
All link buttons should use link_button_click event.

Thank you,
Simon

Nov 18 '05 #8
Simon,

You may want to check out some sample code I've placed on my website.
www.aboutfortunate.com - click the "Code Library" link in the upper right
corner and then use the search box there to search for: "Dynamic Control". I
think some of the sample code will help you get some ideas of how to handle
this.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"simon" <si*********@stud-moderna.si> wrote in message
news:%2***************@TK2MSFTNGP09.phx.gbl...
I have dataRepeater and ItemTemplate:

<itemTemplate>
<%# writeLine(0,DataBinder.Eval(Container.DataItem,
"ts_id"),DataBinder.Eval(Container.DataItem, "timeStart"))%>
</itemTemplate>

In write line function I check if there exsists something and if it does, I would like to add linkButton else something else.
When user clicks this button some pannel will show and so on.

Is there some other way?

Second question.

I have couple lists of codes. When user clicks the button, Iwould like to
show this codes to him in some combo box.
Then he choose one and codes dissapear.

I can do that like combo box on panel and set panel's visibility to
false.When user click the button set visibility to true and when choose the code set visibility again to false.But that means that every time user want this page all my lists must be loaded to him.That means slow page. I can do that dynamically and load this scripts to him only when user click buton or with javaScript and window.open method.

Is there some other method?

Thank you,
Simon

But dynamically, this won't work

"Martin Dechev" <de*******@hotmail.com> wrote in message
news:%2***************@TK2MSFTNGP09.phx.gbl...
Hi, Simon,

You should add the control independant on IsPostBack. i.e.:

"simon" <si*********@stud-moderna.si> wrote in message
news:uw*************@tk2msftngp13.phx.gbl...
On code behind file:

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


' If Not Page.IsPostBack Then
Dim ctrl As New LinkButton
ctrl.ID = "link1"
ctrl.Text = "link create"
ctrl.CommandArgument = "myargument"
ctrl.CommandName = "mycommandname"
AddHandler ctrl.Click, AddressOf link_button_click
plcCategory.Controls.Add(ctrl)


' End If
End Sub


IMO a more appropriate place to dynamically add controls is the Page_Init
automatic handler or overriding the protected Contsruct method.

Hope this helps
Martin

Sub link_button_click(ByVal sender As Object, ByVal e As

System.EventArgs) Response.Write("test")
End Sub

AND page:

<form id="Form1" method="post" runat="server">
<asp:PlaceHolder ID="plcCategory" Runat="server"></asp:PlaceHolder> </form>

What is wrong here?
I would like to dynamically add more link buttons. Here is example for one and click event doesn't work.
All link buttons should use link_button_click event.

Thank you,
Simon


Nov 18 '05 #9

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

Similar topics

2
by: RobG | last post by:
I am trying to dynamically add an onclick to an element, however I just can't get the syntax right. consider the following function: function doClick (evt,x) { // do things with evt and x } ...
8
by: simon | last post by:
On code behind file: Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load If Not Page.IsPostBack Then Dim ctrl As New LinkButton ctrl.ID =...
4
by: hb | last post by:
Hi, When I add an asp:button (ex: id=btnLog) on home.aspx, I need to create btnLog_Click() event in home.aspx.cs, and also link this event and the button in OnInit() method by adding:...
2
by: djc | last post by:
On the page_load event I am querying a database and binding data to some text boxes, list boxes, and a repeater control. When the page loads it uses the value of one of the database fields (status)...
1
by: vj | last post by:
How i can populate all fileds dynamically in jsp page based on contents found in xml file? I have written jsp servlets and java class file. i transferred automatic data from jsp to servlet then to...
0
by: vijendra | last post by:
How i can populate all fileds dynamically in jsp page based on contents found in xml file?I have written jsp servlets and java class file. i transferred automatic data from jsp to servlet then to...
2
by: jmarendo | last post by:
Hello, After reading through the "Table Basics - DOM - Refer to table cells" example at mredkj.com , I modified the code for my own purposes. In the modified version, I create a hyperlink and...
3
by: Mark | last post by:
Assume you want to dynamically add one to many link button controls to a web page dynamically at run time. Each link button needs to post back and execute code. As the link buttons are created at...
5
by: Amoril | last post by:
I've read quite a few different message on various boards and for some reason I'm still having trouble wrapping my head around this viewstate maintenance and trying to get these dynamically created...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.