page.findcontrol: input type="button"

Posted on 2007-07-24
Last Modified: 2013-11-26
page.findcontrol: input type="button"

I have an html button on an page and wish to add attributes to it at runtime.  With a server control, I would just use mycontrol.attributes.add(..).
However, in this case, I do not want the button to post back, only to call a javascript function, so I elected for an html button.
However, the issue I'm running into is setting the attributes at page_load.
I am unable to find the control using something like:

dim myBtn as HtmlInputButton = ctype(page.findcontrol("btnAddGroup"),HtmlInputButton)

The button is declared as follows:

<input id="btnAddGroup" type="button" value=">>" class="btn" />

How can add attributes to this control at runtime?
Question by:byrd48
    LVL 9

    Accepted Solution

    The problem here is you need to add runat=server attribute in your input tag as follows:

    input id="btnAddGroup" type="button" value=">>" class="btn"  runat=server/>

    This will allow you get the object in Codebehind filw where you can do attributes.add()


    Chirag Patel.
    LVL 17

    Expert Comment

    like this;

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
    This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    737 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

    21 Experts available now in Live!

    Get 1:1 Help Now