direct cast an asp button inisde a listview layout template


I am trying access a button in a list view layout template none of this will work , any suggestion?


Protected Sub ListView1_LayoutCreated(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListView1.LayoutCreated

        'Dim mybtnPrint As Button = CType(ListView1.FindControl("btnPrint1"), Button)
        'Dim myButtonPrint As Literal = DirectCast(ListView1.FindControl("btnPrint1"), Literal)
        'Dim rickButton As Button = DirectCast(ListView1.Controls(1).FindControl("btnPrint1"), Button)
        ' mybtnPrint.Attributes.Add("Onclick", "getPrint('print_area');")

        'Dim dataview As ListViewDataItem = TryCast(ListViewDataItem.DataItem, ListViewDataItem)
    End Sub

Open in new window

LVL 9
TonyRebaAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
puru1981Connect With a Mentor Commented:
ok then try this

Dim mybtnPrint As System.Web.UI.Controls.Button = CType(ListView1.FindControl("btnPrint1"), System.Web.UI.Controls.Button)

or remove the System.Windows.Forms from the Import statement. it will work.
0
 
puru1981Commented:
can you share the aspx of the page?

may be it is htmlbutton which you are trying to convert into Button
0
 
TonyRebaAuthor Commented:
no, is actually an asp button inside a Listview asp.net 3.5 control



<asp:Button ID="btnPrint1" runat="server" Text="Print Selected Providers" onClientclick="javascript:CallPrint('form1')" />

Open in new window

0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
puru1981Commented:
is it within the itemtemplate and alternateitemtemplate of the listview?
0
 
TonyRebaAuthor Commented:
is on the layoutemplate of the listview
0
 
puru1981Commented:
in the post below table tr and td which are container for the control is runat server and it is working fine for them. can you try this.

http://forums.asp.net/t/1298231.aspx
0
 
TonyRebaAuthor Commented:
I tried that already but mine is a Button not a Link Button and VS2010 gives me an error!!
0
 
puru1981Commented:
it should work actually. what is the error you are getting?
0
 
TonyRebaAuthor Commented:
'Button' is ambiguous , imported from the namespaces or types 'System.Windows.Forms,System.Web.UI.Controls'.
0
 
TonyRebaAuthor Commented:
thankyou that made the trick
0
All Courses

From novice to tech pro — start learning today.