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

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?
Who is Participating?
b1xml2Connect With a Mentor Commented:
<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)
tusharashahConnect With a Mentor Commented:
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;")

useless_eaterAuthor Commented:
I'll try that and report back.  But I'd still like to know if I can find an html control.
useless_eaterAuthor Commented:
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.

so all is well then =)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.