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

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

can you share the aspx of the page?

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

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

Open in new window

is it within the itemtemplate and alternateitemtemplate of the listview?
C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

TonyRebaAuthor Commented:
is on the layoutemplate of the listview
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.
TonyRebaAuthor Commented:
I tried that already but mine is a Button not a Link Button and VS2010 gives me an error!!
it should work actually. what is the error you are getting?
TonyRebaAuthor Commented:
'Button' is ambiguous , imported from the namespaces or types 'System.Windows.Forms,System.Web.UI.Controls'.
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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
TonyRebaAuthor Commented:
thankyou that made the trick
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.