I can't find an HTML Button with the Controls.FindControl method!

Posted on 2005-05-02
Last Modified: 2008-01-16
I have an HTML button on my page opposed to an ASP.Net server control as I don't want the form to be posted back when I click on it.  In the form load event I want to add a bit of javascript using the attributes collection e.g.


I'm trying to get a reference to the HTML button control using the FindControl method but this can't seem to find the button on my page e.g.

myButton = ctype(me.controls.findcontrol("btnPrint"),HtmlButton))

I'v tried doing...

myButton = ctype(me.controls("Form1").controls.findcontrol("btnPrint"),HtmlButton))

but that doesn't work either, they both return Nothing

So how do I get a reference to an HTML control?
Question by:useless_eater
    LVL 18

    Assisted Solution

    you can make your button as Server control and return false from your JavaScript to prevent Postback.

    Try this:

    Button1.Attributes.Add("OnClick", "return false;")


    Author Comment

    I'll try that and report back.  But I'd still like to know if I can find an html control.
    LVL 23

    Accepted Solution

    <button id="btnPrint" runat="server">Print</button>

    How are you adding the button? Statically or Dynamically.

    If it is statically, then is there any Control that contains the button.

    Dim myButton As HtmlButton = CType(FindControl("btnPrint"),HtmlButton)

    Author Comment

    I'm adding the control at design time.

    Having looked at your example b1xml2 I realise my mistake, I forgot to put the runat=server property in my tag.  It's finding it now.

    LVL 23

    Expert Comment

    so all is well then =)

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Join & Write a Comment

    In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
    I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…

    746 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

    14 Experts available now in Live!

    Get 1:1 Help Now