Solved

direct cast an asp button inisde a listview layout template

Posted on 2010-08-27
10
627 Views
Last Modified: 2013-11-27

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

0
Comment
Question by:TonyReba
  • 5
  • 5
10 Comments
 
LVL 9

Expert Comment

by:puru1981
ID: 33542114
can you share the aspx of the page?

may be it is htmlbutton which you are trying to convert into Button
0
 
LVL 9

Author Comment

by:TonyReba
ID: 33542137
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
 
LVL 9

Expert Comment

by:puru1981
ID: 33542253
is it within the itemtemplate and alternateitemtemplate of the listview?
0
 
LVL 9

Author Comment

by:TonyReba
ID: 33542281
is on the layoutemplate of the listview
0
 
LVL 9

Expert Comment

by:puru1981
ID: 33542495
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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 9

Author Comment

by:TonyReba
ID: 33542585
I tried that already but mine is a Button not a Link Button and VS2010 gives me an error!!
0
 
LVL 9

Expert Comment

by:puru1981
ID: 33542844
it should work actually. what is the error you are getting?
0
 
LVL 9

Author Comment

by:TonyReba
ID: 33542862
'Button' is ambiguous , imported from the namespaces or types 'System.Windows.Forms,System.Web.UI.Controls'.
0
 
LVL 9

Accepted Solution

by:
puru1981 earned 500 total points
ID: 33542909
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
 
LVL 9

Author Closing Comment

by:TonyReba
ID: 33543062
thankyou that made the trick
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Read about why website design really matters in today's demanding market.
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now