Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 659
  • Last Modified:

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

0
TonyReba
Asked:
TonyReba
  • 5
  • 5
1 Solution
 
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
 
puru1981Commented:
is it within the itemtemplate and alternateitemtemplate of the listview?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
puru1981Commented:
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
 
TonyRebaAuthor Commented:
thankyou that made the trick
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

  • 5
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now