473,396 Members | 1,864 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,396 software developers and data experts.

Link Buttons on the fly

Hi everyone,
I'm have a table in my aspx page that has 1 row which will contain 0 or
more cells. Each cell will contain a link button. My code is something
like this:

Dim lb As New System.Web.UI.WebControls.LinkButton
lb.Text = row("filename")

lb.CommandName = "GetAttachment"

lb.CommandArgument = row("attachmentID")

lb.Attributes("onclick") = "LinkButton_Command"

Dim cell As New System.Web.UI.WebControls.TableCell

cell.Controls.Add(lb)

cell.Visible = True

tblAttachments.Rows(0).Cells.Add(cell)

Where row is a row from a datatable in a dataset. Everything works fine
except that the "onclick" attribute doesn't work. If i manually code a link
button into my form, then it works fine. The problem "I think" is how the
control is being rendered. When I manually code the link button like:
"<asp:linkbutton text="button" Oncommand="LinkButton_Command"
CommandName="GetAttachment" CommandArgument="95" Runat=server/>" it renders
like this:
<a href="javascript:__doPostBack('_ctl0','')">button</a>. But when I make
it like in the above code, It renders like this:
<a onclick="LinkButton_Command" runat="server"
href="javascript:__doPostBack('_ctl1','')">FFIS2.v sd</a>, which is not
right. Anybody have any suggestions on this? Thanks alot,

Matt

PS, using oncommand instead of onclick does work either

Nov 18 '05 #1
4 1671
EMW
Try this:

lb.Attributs.add("OnClick","LinkButton_Command")

rg,
Eric
"Matt MacDonald" <ma******@hotmail.com> schreef in bericht
news:OX**************@TK2MSFTNGP09.phx.gbl...
Hi everyone,
I'm have a table in my aspx page that has 1 row which will contain 0 or
more cells. Each cell will contain a link button. My code is something
like this:

Dim lb As New System.Web.UI.WebControls.LinkButton
lb.Text = row("filename")

lb.CommandName = "GetAttachment"

lb.CommandArgument = row("attachmentID")

lb.Attributes("onclick") = "LinkButton_Command"

Dim cell As New System.Web.UI.WebControls.TableCell

cell.Controls.Add(lb)

cell.Visible = True

tblAttachments.Rows(0).Cells.Add(cell)

Where row is a row from a datatable in a dataset. Everything works fine
except that the "onclick" attribute doesn't work. If i manually code a link button into my form, then it works fine. The problem "I think" is how the
control is being rendered. When I manually code the link button like:
"<asp:linkbutton text="button" Oncommand="LinkButton_Command"
CommandName="GetAttachment" CommandArgument="95" Runat=server/>" it renders like this:
<a href="javascript:__doPostBack('_ctl0','')">button</a>. But when I make
it like in the above code, It renders like this:
<a onclick="LinkButton_Command" runat="server"
href="javascript:__doPostBack('_ctl1','')">FFIS2.v sd</a>, which is not
right. Anybody have any suggestions on this? Thanks alot,

Matt

PS, using oncommand instead of onclick does work either

Nov 18 '05 #2
Jos
Matt MacDonald wrote:
Hi everyone,
I'm have a table in my aspx page that has 1 row which will contain
0 or more cells. Each cell will contain a link button. My code is
something like this:

Dim lb As New System.Web.UI.WebControls.LinkButton
lb.Text = row("filename")

lb.CommandName = "GetAttachment"

lb.CommandArgument = row("attachmentID")

lb.Attributes("onclick") = "LinkButton_Command"

<snip>

This last line will add a client-side handler, not a server-side one.

Use

AddHandler lb.OnClick, AddressOf LinkButton_Command

instead.

--

Jos
Nov 18 '05 #3
I think I tried that already, but I'll take a look at it again, thanks.
"EMW" <SomeOne@MicroSoftdotCom> wrote in message
news:40**********************@dreader2.news.tiscal i.nl...
Try this:

lb.Attributs.add("OnClick","LinkButton_Command")

rg,
Eric
"Matt MacDonald" <ma******@hotmail.com> schreef in bericht
news:OX**************@TK2MSFTNGP09.phx.gbl...
Hi everyone,
I'm have a table in my aspx page that has 1 row which will contain 0 or more cells. Each cell will contain a link button. My code is something
like this:

Dim lb As New System.Web.UI.WebControls.LinkButton
lb.Text = row("filename")

lb.CommandName = "GetAttachment"

lb.CommandArgument = row("attachmentID")

lb.Attributes("onclick") = "LinkButton_Command"

Dim cell As New System.Web.UI.WebControls.TableCell

cell.Controls.Add(lb)

cell.Visible = True

tblAttachments.Rows(0).Cells.Add(cell)

Where row is a row from a datatable in a dataset. Everything works fine
except that the "onclick" attribute doesn't work. If i manually code a

link
button into my form, then it works fine. The problem "I think" is how the control is being rendered. When I manually code the link button like:
"<asp:linkbutton text="button" Oncommand="LinkButton_Command"
CommandName="GetAttachment" CommandArgument="95" Runat=server/>" it

renders
like this:
<a href="javascript:__doPostBack('_ctl0','')">button</a>. But when I make it like in the above code, It renders like this:
<a onclick="LinkButton_Command" runat="server"
href="javascript:__doPostBack('_ctl1','')">FFIS2.v sd</a>, which is not
right. Anybody have any suggestions on this? Thanks alot,

Matt

PS, using oncommand instead of onclick does work either


Nov 18 '05 #4
Nope, That didn't work either, i got the same rendered tag
"Matt MacDonald" <ma******@hotmail.com> wrote in message
news:Oc**************@TK2MSFTNGP09.phx.gbl...
I think I tried that already, but I'll take a look at it again, thanks.
"EMW" <SomeOne@MicroSoftdotCom> wrote in message
news:40**********************@dreader2.news.tiscal i.nl...
Try this:

lb.Attributs.add("OnClick","LinkButton_Command")

rg,
Eric
"Matt MacDonald" <ma******@hotmail.com> schreef in bericht
news:OX**************@TK2MSFTNGP09.phx.gbl...
Hi everyone,
I'm have a table in my aspx page that has 1 row which will contain 0 or more cells. Each cell will contain a link button. My code is something like this:

Dim lb As New System.Web.UI.WebControls.LinkButton
lb.Text = row("filename")

lb.CommandName = "GetAttachment"

lb.CommandArgument = row("attachmentID")

lb.Attributes("onclick") = "LinkButton_Command"

Dim cell As New System.Web.UI.WebControls.TableCell

cell.Controls.Add(lb)

cell.Visible = True

tblAttachments.Rows(0).Cells.Add(cell)

Where row is a row from a datatable in a dataset. Everything works fine except that the "onclick" attribute doesn't work. If i manually code
a
link
button into my form, then it works fine. The problem "I think" is how

the control is being rendered. When I manually code the link button like:
"<asp:linkbutton text="button" Oncommand="LinkButton_Command"
CommandName="GetAttachment" CommandArgument="95" Runat=server/>" it

renders
like this:
<a href="javascript:__doPostBack('_ctl0','')">button</a>. But when I make it like in the above code, It renders like this:
<a onclick="LinkButton_Command" runat="server"
href="javascript:__doPostBack('_ctl1','')">FFIS2.v sd</a>, which is not
right. Anybody have any suggestions on this? Thanks alot,

Matt

PS, using oncommand instead of onclick does work either



Nov 18 '05 #5

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

Similar topics

3
by: rachel | last post by:
Hi all, I am new in ASP.Net. I have a question on link multiple web forms together. Here is the scenario: I create an Index.aspx WebForm which consists of a banner and three navigator...
0
by: Steve Lloyd | last post by:
Hi, I am having lots of problems when using a link button in a page that include modules, it is very strange, the javascript that is generated to submit the form comes up with an error and does...
1
by: brian | last post by:
'visual studio 2002 pro 1.0 framwork' I am creating dynamic Link buttons on my intranet site and assigning a click_event to them. A user clicks a link and I call the method to recreate the...
1
by: Gopal Krish | last post by:
I'm have coded a simple menu (using link buttons as menu items) in a user control to be reused across many ASPX pages. In the page_load method I dynamically create the link buttons as follows ...
26
by: Mica Cooper | last post by:
Hi, I need to pass some info in a javascript submit. <a href="javascript:document.formName.submit();">Submit Form</a> Normally a link would do page.jsp?x1=1&x2=2&x3=3 and you would pull x1,...
0
by: prashantnurvi | last post by:
I have programaticaaly created several Link Buttons on my ASPX page, I would like to raise the Click event of these Link buttons, passing in appropriate parameters depending on the Link button I...
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: Matt | last post by:
Creating Dynamic aspnet link buttons with in user control, Then i use the control on ever page with wraped with master page. I get the url of the link buttons from xml. Parameter from xml also...
9
by: lilOlMe | last post by:
Hi there! I have generated a GridView that looks something like: SportName| CompanyNameX |CompanyNameY |CompanyNameZ Hockey.....| Shipping------------ |Accounting-------- |Shipping------------...
3
by: =?Utf-8?B?UGxhdGVyaW90?= | last post by:
I have link buttons in a Gridview that, depending on the value in another column (Not the Key column) will need to be disabled. For example, (Column2 has link buttons) Column1 ...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...

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.