Solved

direct cast an asp button inisde a listview layout template

Posted on 2010-08-27
10
630 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
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
 
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
hbo knew my windows software 4 62
Get month and date in a format 4 32
IDE for Python 5 21
PowerShell: ForEach ($y in $x.licenses | where {....} 3 23
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…
Because your company can’t afford for you to make SEO mistakes, you’ll want to ensure you’re taking the right steps each and every time you post a new piece of content. This list of optimization do’s and don’ts can help you become an SEO wizard.
This video teaches users how to migrate an existing Wordpress website to a new domain.
The viewer will learn how to dynamically set the form action using jQuery.

837 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