Button on_Click..?

Discussion in 'ASP .Net Web Controls' started by Kent Johnson, Sep 20, 2003.

  1. Kent Johnson

    Kent Johnson Guest

    Hi all,

    I'm new to Asp.Net and I have a simple:

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles Button1.Click
    TextBox1.Text = "This is a test"
    End Sub

    "This is a test" works in a Windows app. but not in Asp.Net web application.
    If I push the button in a browser nothing happens. I have installed the Net
    framework on the server.

    What can be wrong?

    /Kent J.
     
    Kent Johnson, Sep 20, 2003
    #1
    1. Advertising

  2. You have to set the event handler at a different time. Usually in code
    behind when the page is initialised with the OnInit event. VS.Net will
    automatically generate a routine called InitializeComponent that simply just
    assigned all the event handlers for the page, inlcluding the Page_Load
    event, and then calls InitializeComponent from the OnInit event. In the code
    you would have something like:
    Button1.Click += new EventHandler(Button1_Click) (I'm using C# so the syntax
    may be a little off).

    If you're not using code behind, check out some of the examples of dealing
    with events at:
    http://samples.gotdotnet.com/quickstart/aspplus/doc/webserverctrls.aspx#handling

    Hope this helps,
    Mark Fitzpatrick
    Microsoft MVP - FrontPage


    "Kent Johnson" <> wrote in message
    news:l4Wab.29314$...
    > Hi all,
    >
    > I'm new to Asp.Net and I have a simple:
    >
    > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
    > System.EventArgs) Handles Button1.Click
    > TextBox1.Text = "This is a test"
    > End Sub
    >
    > "This is a test" works in a Windows app. but not in Asp.Net web

    application.
    > If I push the button in a browser nothing happens. I have installed the

    Net
    > framework on the server.
    >
    > What can be wrong?
    >
    > /Kent J.
    >
    >
     
    Mark Fitzpatrick, Sep 20, 2003
    #2
    1. Advertising

  3. Kent Johnson

    James Radke Guest

    Kent,

    Are you sure that the Button control properties include the runat=server
    property?

    This is the property of the webcontrol that tells it to execute the code
    that is placed in the codebehind area.... Otherwise it will never run the
    code...

    Jim

    "Kent Johnson" <> wrote in message
    news:l4Wab.29314$...
    > Hi all,
    >
    > I'm new to Asp.Net and I have a simple:
    >
    > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
    > System.EventArgs) Handles Button1.Click
    > TextBox1.Text = "This is a test"
    > End Sub
    >
    > "This is a test" works in a Windows app. but not in Asp.Net web

    application.
    > If I push the button in a browser nothing happens. I have installed the

    Net
    > framework on the server.
    >
    > What can be wrong?
    >
    > /Kent J.
    >
    >
     
    James Radke, Sep 20, 2003
    #3
  4. Kent Johnson

    Sacred Guest

    Don't know if you fixed it..

    But couple of different things without knowing your
    stuff. Button1 has to be declared in code behind and it
    has to match the exact ID of your html or web control in
    your html page.

    The other is it Button1 in code behind has to be declared
    using WITHEVENTS.

    If you are using an image button you have to use a
    different variable for eventargs.

    Hope this helps

    Sacred


    >-----Original Message-----
    >Hi all,
    >
    >I'm new to Asp.Net and I have a simple:
    >
    >Private Sub Button1_Click(ByVal sender As System.Object,

    ByVal e As
    >System.EventArgs) Handles Button1.Click
    >TextBox1.Text = "This is a test"
    >End Sub
    >
    >"This is a test" works in a Windows app. but not in

    Asp.Net web application.
    >If I push the button in a browser nothing happens. I have

    installed the Net
    >framework on the server.
    >
    >What can be wrong?
    >
    >/Kent J.
    >
    >
    >.
    >
     
    Sacred, Sep 22, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Purvi T
    Replies:
    0
    Views:
    937
    Purvi T
    Oct 19, 2004
  2. Wes Weems
    Replies:
    1
    Views:
    505
    Natty Gur
    Jul 20, 2003
  3. Chris Lane
    Replies:
    4
    Views:
    11,333
    Chris Lane
    Nov 17, 2003
  4. Weston Weems
    Replies:
    2
    Views:
    441
    Weston Weems
    Sep 3, 2004
  5. Stephen Noronha

    on_click of Button

    Stephen Noronha, Oct 21, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    526
    Stephen Noronha
    Oct 21, 2005
Loading...

Share This Page