form1_Load not firing

  • Thread starter Thread starter tshad
  • Start date Start date
T

tshad

I just started working with VS.net 2003 and am trying to get a Web Service
running. I got it working fine in VB.Net, but I can't seem to get it to go
to the Form_Load handler to call the service. From the book it is pretty
straight forward.

I added the form1_Load function to the default code:

********************************************************
static void Main()
{
Application.Run(new Form1());
}

private void Form1_Load(object sender, System.EventArgs e)
{
localhost.Service1 WebServiceObject;
WebServiceObject = new localhost.Service1();
string Result;
textBox1.Text = "This is a test Before the Try/Catch secion";
try
{
textBox1.Text = WebServiceObject.HelloWorld();
}
catch (Exception Ex)
{
textBox1.Text = "Web Service Exception: " + Ex.Message;
}
}
private void textBox1_TextChanged(object sender, System.EventArgs e)
{

}
}
}
***********************************************************************

The program works fine and stepping through it goes first to Main but never
goes to Form1_Load.

The Form opens and the default text that was in the box is still there.

Why doesn't the Form1_Load handler work? The book doesn't mention having to
do anything special to get it to run. It says that when you first run the
application, the program will call the form's Load handler (Form1_Load).
Did it leave out a step?

Thanks,

Tom
 
did you add the event handler association also?

this.Load += new System.EventHandler(this.Form1_Load);

Alan.
 
did you add the event handler association also?

this.Load += new System.EventHandler(this.Form1_Load);

I didn't put it in myself.

I assumed that since it was already there, that that handler would be there.

I was following an example from a book and they didn't mention it. They
said it would automatically go to that procedure. I assume that that was
wrong.

Where would I put this code?

Thanks,

Tom
 
When one adds the Form Load event handler using the IDE - say by double
clicking on the form body in designer or using the dropdown to select
the load event, the IDE will add the empty routine AND add a line to
'Windows Form Designer Generated Code' region


//
// frmMain
//

....

this.Load += new System.EventHandler(this.frmMain_Load);

which associates the routine with the Load event.


The simplest solution is to

1) remove your load handler.
2) Double click on the form body to add a new load handler - with the
correct event/handler assoc.
3) copy the code from your routine to the new one


General point... this is the VB.Net rather than C# NG. You may get
better results posting the question to
micosoft.public.dotnet.languages.csharp


hth,
Alan.
 
When one adds the Form Load event handler using the IDE - say by double
clicking on the form body in designer or using the dropdown to select
the load event, the IDE will add the empty routine AND add a line to
'Windows Form Designer Generated Code' region

What was confusing is that I have the form_Load event set in the
properties/General/Startup Object. But it still went to Main first. I
would have thought it would set the handler there, but I guess not.
//
// frmMain
//

...

this.Load += new System.EventHandler(this.frmMain_Load);

which associates the routine with the Load event.


The simplest solution is to

1) remove your load handler.
2) Double click on the form body to add a new load handler - with the
correct event/handler assoc.
3) copy the code from your routine to the new one


General point... this is the VB.Net rather than C# NG. You may get
better results posting the question to
micosoft.public.dotnet.languages.csharp

Actually, I have been going back and forth between vb.net and C# in my
examples, so I don't even remember which project was causing me the problem.

I am used to coding my project directly using DW and am trying to get used
to the IDE to allow me to write Web Services and Windows Services. I was
going to wait for VS 2005, as I have heard that is much better and some
people don't like 2003, but I am under the gun here and had to bite the
bullet now.

Thanks,

Tom
 

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

Similar Threads


Back
Top