locked
using vbscript to declare the function that handles the button onclick event RRS feed

  • Question

  • User-1881872671 posted

    hi all, i want to know how to use vbscript to declare the function that handles the button onclick event~

    or set a function that handles all button onlick event! both will do~

    i.e) ihave a function

    "sub xxx()

    end sub"

    and i generate the buttons using vbscript. i can declare the button id, text without problem.

    --dim obj as new button()

             obj.id="aaa“

             obj.text="ooo"

    the above lines work just fine

    but when i write obj.onclick = "xxx", it doesn't work.

    anyway to deal with that?  by making settings on the function to handle all button onlick event is also acceptible for me!

    thanks in advance 

    Saturday, April 10, 2010 5:11 AM

Answers

  • User-821857111 posted

    Oh, I see. You want to add a server-side button click event handler. In VB, I believe you have to use AddHandler:

    AddHandler objbut.Click, AddressOf comeon

    Have a read of this: http://forums.asp.net/t/1186195.aspx




    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, April 10, 2010 3:33 PM

All replies

  • User-821857111 posted

    I assume you actually mean VB, not VBScript? If you want to add a clientside click event to a button in server-side code, you need to assign the OnClientClick property, not onClick:

    obj.OnClientClick = "xxx"


    Saturday, April 10, 2010 10:43 AM
  • User-1881872671 posted

    hi, thanks for your reply. but it didn't work.
    below is the code. i hope you can help me again~~ thanks . 

    **ph stands for placeholder control

    ============

    objreader = cmd.executereader()
            While objreader.read()
                Dim objbut As New Button()
                i = i + 1
                objbut.ID = "but" & i
                objbut.Text = objreader("cate").ToString()
                objbut.OnClientClick = "comeon"
                ph.Controls.Add(objbut)
     Dim hbr As HtmlControl = New HtmlGenericControl("br") ph.controls.add(hbr) Response.Write(objreader("cate").tostring()) If initsubcate Is Nothing Then initsubcate = objreader("cate").tostring() End If Response.Write("~~") End While Response.Write(initsubcate) objreader.close() conn.close() End Sub Sub comeon(ByVal obj As Object, ByVal e As EventArgs) Response.Write("comeonran") End Sub

    ==============

    Saturday, April 10, 2010 12:26 PM
  • User-821857111 posted

    Oh, I see. You want to add a server-side button click event handler. In VB, I believe you have to use AddHandler:

    AddHandler objbut.Click, AddressOf comeon

    Have a read of this: http://forums.asp.net/t/1186195.aspx




    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, April 10, 2010 3:33 PM
  • User-1881872671 posted

    that is exactly what i m looking for. thanks a lot!!

    Sunday, April 11, 2010 5:50 AM