Solved

direct cast an asp button inisde a listview layout template

Posted on 2010-08-27
10
626 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
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:
The viewer will learn how to count occurrences of each item in an array.

744 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

11 Experts available now in Live!

Get 1:1 Help Now