Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Link Button creation problem

Reply
Thread Tools

Link Button creation problem

 
 
Burak
Guest
Posts: n/a
 
      09-18-2003
Hello,

I have some issues with creating link buttons dynamically.

This is my link button creation string:

strUrl = "<asp:LinkButton CommandName='Onet3_Cd'
onfiltered='LinkButton_Command' runat='server' " & _
"Text='" & rdrOnet3("ONET3_TITLE") & "'
CommandArgument='" & rdrOnet3("ONET3_CD") & "' id='lb"
& i & "'></asp:LinkButton>"

Dim ctrl As Control =
Page.ParseControl(strUrl.ToString())
plcCategory.Controls.Add(ctrl) ' place holder object

The link button shows up fine when I run this, but
when I click on the link, it doesn't take me to

Sub LinkButton_Command(ByVal sender As Object, ByVal e
As CommandEventArgs)

Dim strDesc As String
strDesc = sender.text
Response.Write(sender.text)
End Sub

I based my code on

http://msdn.microsoft.com/library/de...ref/html/frlr\
fsystemwebuiwebcontrolslinkbuttonclasscommandnamet opic.asp

The click works if I hard code the link button on the
html page, but if I create it dynamically, the click
does not take me to the above sub.

Do you know how to fix this?

Thanks,

Burak
 
Reply With Quote
 
 
 
 
vMike
Guest
Posts: n/a
 
      09-19-2003
You might try something like this. An alternative is to take out the
withevents and the comment out the handler section and then put in the lines
I have commented out.

<%@ Page Language="vb" Strict=True %>
<html>
<script language="vb" runat="server">
Protected Dim Withevents ctrl as New linkbutton
Sub Page_Load(sender as object, e as EventArgs)
'Dim ctrl as new linkbutton 'add this if withevents line taken out
ctrl.id="link1"
ctrl.text = "link create"
ctrl.commandargument = "myargument"
ctrl.commandname = "mycommandname"
'addhandler ctrl.click, addressof LinkButton_Command 'add this if
withevents line taken out
plcCategory.Controls.Add(ctrl)
end sub

Sub LinkButton_Command(ByVal sender As Object, ByVal e As EventArgs) handles
ctrl.click 'comment after handers if withevents is removed
Dim strDesc As String
strDesc = directcast(sender,linkbutton).text
Response.Write(strDesc & "<br>")
Response.Write(directcast(sender,linkbutton).comma ndname & "<br>")
Response.write(directCast(sender,linkbutton).comma ndargument & "<br>")

End Sub

</script>
<form id="form1" runat="server">
<asplaceHolder id="plcCategory"
runat="Server"/>

</form>

</html>
"Burak" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) m...
> Hello,
>
> I have some issues with creating link buttons dynamically.
>
> This is my link button creation string:
>
> strUrl = "<asp:LinkButton CommandName='Onet3_Cd'
> onfiltered='LinkButton_Command' runat='server' " & _
> "Text='" & rdrOnet3("ONET3_TITLE") & "'
> CommandArgument='" & rdrOnet3("ONET3_CD") & "' id='lb"
> & i & "'></asp:LinkButton>"
>
> Dim ctrl As Control =
> Page.ParseControl(strUrl.ToString())
> plcCategory.Controls.Add(ctrl) ' place holder object
>
> The link button shows up fine when I run this, but
> when I click on the link, it doesn't take me to
>
> Sub LinkButton_Command(ByVal sender As Object, ByVal e
> As CommandEventArgs)
>
> Dim strDesc As String
> strDesc = sender.text
> Response.Write(sender.text)
> End Sub
>
> I based my code on
>
>

http://msdn.microsoft.com/library/de...ref/html/frlr\
> fsystemwebuiwebcontrolslinkbuttonclasscommandnamet opic.asp
>
> The click works if I hard code the link button on the
> html page, but if I create it dynamically, the click
> does not take me to the above sub.
>
> Do you know how to fix this?
>
> Thanks,
>
> Burak



 
Reply With Quote
 
 
 
 
Burak
Guest
Posts: n/a
 
      09-22-2003
Hi,

Thank you this works fine for one linkbutton.

How can I have a bunch of list buttons arrangd ina vertical fashion?

Thank you,

Burak


"vMike" <(E-Mail Removed)> wrote in message news:<bkfggm$cq7$(E-Mail Removed)>...
> You might try something like this. An alternative is to take out the
> withevents and the comment out the handler section and then put in the lines
> I have commented out.
>
> <%@ Page Language="vb" Strict=True %>
> <html>
> <script language="vb" runat="server">
> Protected Dim Withevents ctrl as New linkbutton
> Sub Page_Load(sender as object, e as EventArgs)
> 'Dim ctrl as new linkbutton 'add this if withevents line taken out
> ctrl.id="link1"
> ctrl.text = "link create"
> ctrl.commandargument = "myargument"
> ctrl.commandname = "mycommandname"
> 'addhandler ctrl.click, addressof LinkButton_Command 'add this if
> withevents line taken out
> plcCategory.Controls.Add(ctrl)
> end sub
>
> Sub LinkButton_Command(ByVal sender As Object, ByVal e As EventArgs) handles
> ctrl.click 'comment after handers if withevents is removed
> Dim strDesc As String
> strDesc = directcast(sender,linkbutton).text
> Response.Write(strDesc & "<br>")
> Response.Write(directcast(sender,linkbutton).comma ndname & "<br>")
> Response.write(directCast(sender,linkbutton).comma ndargument & "<br>")
>
> End Sub
>
> </script>
> <form id="form1" runat="server">
> <asplaceHolder id="plcCategory"
> runat="Server"/>
>
> </form>
>
> </html>
> "Burak" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed) m...
> > Hello,
> >
> > I have some issues with creating link buttons dynamically.
> >
> > This is my link button creation string:
> >
> > strUrl = "<asp:LinkButton CommandName='Onet3_Cd'
> > onfiltered='LinkButton_Command' runat='server' " & _
> > "Text='" & rdrOnet3("ONET3_TITLE") & "'
> > CommandArgument='" & rdrOnet3("ONET3_CD") & "' id='lb"
> > & i & "'></asp:LinkButton>"
> >
> > Dim ctrl As Control =
> > Page.ParseControl(strUrl.ToString())
> > plcCategory.Controls.Add(ctrl) ' place holder object
> >
> > The link button shows up fine when I run this, but
> > when I click on the link, it doesn't take me to
> >
> > Sub LinkButton_Command(ByVal sender As Object, ByVal e
> > As CommandEventArgs)
> >
> > Dim strDesc As String
> > strDesc = sender.text
> > Response.Write(sender.text)
> > End Sub
> >
> > I based my code on
> >
> >

> http://msdn.microsoft.com/library/de...ref/html/frlr\
> > fsystemwebuiwebcontrolslinkbuttonclasscommandnamet opic.asp
> >
> > The click works if I hard code the link button on the
> > html page, but if I create it dynamically, the click
> > does not take me to the above sub.
> >
> > Do you know how to fix this?
> >
> > Thanks,
> >
> > Burak

 
Reply With Quote
 
vMike
Guest
Posts: n/a
 
      09-22-2003
You could use a for... next loop. But if you can , might opt to bind a
datatable or dataview to a datalist template. but I don't know exactly what
you are doing.
Something like this would be in your template page. In you codebehind you
would bind the datalist to your data.

<ASPataList id="Designers" showheader="false" showfooter="false"
repeatcolumns="1" repeatdirection="horizontal" borderwidth="0"
runat="server">
<ItemTemplate>
<asp:LinkButton
Cssclass="designers"
CommandArgument=<%# DataBinder.Eval(Container.DataItem,
"DesignerID") %>
CausesValidation="false"
OnClick="designer_click"
text=<%# DataBinder.Eval(Container.DataItem, "DesignerName")
%>
runat="server">

</asp:LinkButton>
</ItemTemplate>
</ASPataList>
"Burak" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> Hi,
>
> Thank you this works fine for one linkbutton.
>
> How can I have a bunch of list buttons arrangd ina vertical fashion?
>
> Thank you,
>
> Burak
>
>
> "vMike" <(E-Mail Removed)> wrote in message

news:<bkfggm$cq7$(E-Mail Removed)>...
> > You might try something like this. An alternative is to take out the
> > withevents and the comment out the handler section and then put in the

lines
> > I have commented out.
> >
> > <%@ Page Language="vb" Strict=True %>
> > <html>
> > <script language="vb" runat="server">
> > Protected Dim Withevents ctrl as New linkbutton
> > Sub Page_Load(sender as object, e as EventArgs)
> > 'Dim ctrl as new linkbutton 'add this if withevents line taken out
> > ctrl.id="link1"
> > ctrl.text = "link create"
> > ctrl.commandargument = "myargument"
> > ctrl.commandname = "mycommandname"
> > 'addhandler ctrl.click, addressof LinkButton_Command 'add this if
> > withevents line taken out
> > plcCategory.Controls.Add(ctrl)
> > end sub
> >
> > Sub LinkButton_Command(ByVal sender As Object, ByVal e As EventArgs)

handles
> > ctrl.click 'comment after handers if withevents is removed
> > Dim strDesc As String
> > strDesc = directcast(sender,linkbutton).text
> > Response.Write(strDesc & "<br>")
> > Response.Write(directcast(sender,linkbutton).comma ndname & "<br>")
> > Response.write(directCast(sender,linkbutton).comma ndargument & "<br>")
> >
> > End Sub
> >
> > </script>
> > <form id="form1" runat="server">
> > <asplaceHolder id="plcCategory"
> > runat="Server"/>
> >
> > </form>
> >
> > </html>
> > "Burak" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed) m...
> > > Hello,
> > >
> > > I have some issues with creating link buttons dynamically.
> > >
> > > This is my link button creation string:
> > >
> > > strUrl = "<asp:LinkButton CommandName='Onet3_Cd'
> > > onfiltered='LinkButton_Command' runat='server' " & _
> > > "Text='" & rdrOnet3("ONET3_TITLE") & "'
> > > CommandArgument='" & rdrOnet3("ONET3_CD") & "' id='lb"
> > > & i & "'></asp:LinkButton>"
> > >
> > > Dim ctrl As Control =
> > > Page.ParseControl(strUrl.ToString())
> > > plcCategory.Controls.Add(ctrl) ' place holder object
> > >
> > > The link button shows up fine when I run this, but
> > > when I click on the link, it doesn't take me to
> > >
> > > Sub LinkButton_Command(ByVal sender As Object, ByVal e
> > > As CommandEventArgs)
> > >
> > > Dim strDesc As String
> > > strDesc = sender.text
> > > Response.Write(sender.text)
> > > End Sub
> > >
> > > I based my code on
> > >
> > >

> >

http://msdn.microsoft.com/library/de...ref/html/frlr\
> > > fsystemwebuiwebcontrolslinkbuttonclasscommandnamet opic.asp
> > >
> > > The click works if I hard code the link button on the
> > > html page, but if I create it dynamically, the click
> > > does not take me to the above sub.
> > >
> > > Do you know how to fix this?
> > >
> > > Thanks,
> > >
> > > Burak



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to (batch) set EXIF date taken and IPTC creation date and creation time for photos with filenames YYMMDDHHMMSS#.jpg? guercheLE@gmail.com Digital Photography 1 10-04-2005 07:15 PM
RE: Link Link Link =?Utf-8?B?REw=?= Windows 64bit 0 05-17-2005 12:15 PM
Re: Link Link Link DANGER WILL ROBINSON!!! Kevin Spencer ASP .Net 0 05-17-2005 10:41 AM
href link to code creation of file and open of that file Ryan ASP .Net 1 11-05-2004 08:37 PM
Problems with Link Button and Button web controls Suzanne ASP .Net Web Controls 0 12-03-2003 02:17 PM



Advertisments