Button on_Click..?

K

Kent Johnson

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.
 
M

Mark Fitzpatrick

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
 
J

James Radke

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
 
S

Sacred

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top