How to call an method with regular HTML input button

Posted on 2005-05-14
Last Modified: 2012-06-21
Hello, How can I call a method in an .vb (.dll) file from a html form submit button. This is what my button code looks like.

<input type="button" onClick="btnAsk_Click" value="Ask &#62;" class="submit" />

and I want it to call this method in that aspx page's codebehind document

     public Sub btnAsk_Click()
          ltlEmailOutput.Text = "test"
    End Sub

I can't use an web control because the code for the button is coming from an xslt document and throws errors when I try to add an web control. Figuring out how to put a web control in an xslt document may also solve my problem. But I think triggering this method with a normal submit button would be fine, any ideas?

Thank You,
Question by:sneidig
    LVL 27

    Expert Comment

    Is it on purpose that you have btnAskClick in your HTML, but btnAskFleet_Click in your codebehind?


    Author Comment

    That was a mistake. I made an edit to correct it that I think should show up. Thanks.
    LVL 23

    Expert Comment

    The marriage between Xml Transforms and the event-driven model of ASP.NET can and has been done. But you must have a stronger grasp of reflection in order to do this. Also, can you perform the transformation (that is in during the Init event) early on?

    Author Comment

    Now I know it can be done. Can you give me an idea of the learning curve for reflections? I found this tutorial though I'm not sure if it will help me or not.

    I don't think I've ever put code in page_init if that's what you're refering too. I'm not sure how that would help me out.

    Thanks for the info.
    LVL 23

    Accepted Solution

    The learning curve is pretty steep and this is even with using C# (I realise that you are using VB.NET). But once you get the hang of it, such knowledge only serves to strenghten your grasp of the need for good design patterns. There is a hybrid also between Xml Transforms and the ASP.NET model
    LVL 23

    Expert Comment

    Youd need to change this:
    <input type="button" onClick="btnAsk_Click" value="Ask &#62;" class="submit" />
    <input type="button" onClick="btnAsk_Click" value="Ask &#62;" class="submit" runat="server" id="btnSubmit" />

    You then get the text from the transformation and parse it like so:

    Dim ctl As Control = Page.ParseControl(<txt>)

    Now comes the interesting part:
    You can loop through the XmlDocument if there is one and hook up the events to methods within this class thru reflection since the output will definitely vary ....

    you hardcode it like so
    Dim btnSubmit As HtmInputButton = CType(ctl.FindControl("btnSubmit"),HtmlInputButton)
    If Not btnSubmit Is Nothing Then AddHandler btnSubmit.Click, AddressOf Me.btnSubmit_Click


    Author Comment

    Thank you. I'll have to continue working on this tomorrow. Have a good nite.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Suggested Solutions

    Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
    Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    755 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

    22 Experts available now in Live!

    Get 1:1 Help Now