Page_Load & ButtonClick?

A

Arpan

When a Button is clicked in a Web Form in an ASPX page, the Form will
post back to itself. Under such circumstances (i.e. when a Button is
clicked), will the Page_Load sub execute first & then will the Click
event function of the Button execute or will the Click event function
of the Button execute first & then will the Page_Load sub execute?

Thanks,

Arpan
 
S

Scott M.

Page_Load will always execute before any event handlers from your web page.

The simple reason being that each time the page is requested (postback or
not), it must be built from scratch as well as the controls on it. You
can't very well have the event handler of a button execute before the button
object exists in the first place.
 
S

Scott M.

A simple test would be to set breakpoints in each event handler and see for
yourself that Page_Load executes first.
 
A

Arpan

Scott, thanks for the response. Prior to posting my query, I had tried
setting breakpoints but I guess breakpoints in Visual Web Developer
2005 doesn't work in the same way as how breakpoints work in VB6.

In VB6, suppose a breakpoint is set on the Click event function of,
say, a CommandButton. Now as soon as the CommandButton is clicked when
the app is executed from the VB IDE, focus shifts back to the VB IDE &
pressing F8 steps over each & every line within the Click event
function of the CommandButton but setting a breakpoint on a sub in the
VWD IDE doesn't behave in the same way. The focus doesn't shift back to
the VWD IDE; in fact nothing happens when a sub which has been
"breakpointed" gets executed when the ASPX page is run in IE (or any
other browser) from the VWD IDE (by clicking the "View in Browser"
button).

So how do I step over each & every line within a sub in VWD? In other
words, how do I utilize the breakpoint feature in VWD 2005?

Thanks once again,

Regards,

Arpan

P.S.: Are you Scott Mitchell, by any chance?
 
A

Arpan

Set your breakpoint and press F5. Stepping works as it did in VB 6.0.

When should F5 be pressed? I set a breakpoint for a sub named btn_Click
(Click event function of a Button). After running the ASPX page in the
browser & without clicking the Button, I came back to the VWD IDE &
pressed F5 but that didn't do the stepping! I again went back to the
browser, clicked the Button, came back to the VWD IDE & pressed F5 but
that didn't step over the code. I even tried pressing F5 in the VWD IDE
without running the ASPX page in a browser but that didn't step over
the code as well. At what point should I press F5?

Arpan
 
S

Scott M.

You don't start the app and then press F5. You press F5 to start the app in
debug mode. Same as in VB 6.0. Hasn't changed at all.
 
A

Arpan

You don't start the app and then press F5. You press F5 to start the app in
debug mode.

But I always find the "Start Debugging" menu item under the "Debug"
menu as well as the "Start Debugging" icon on the toolbar disabled. How
do I enable it?

Arpan
 
S

Scott M.

You many not have debugging enabled for the site you are working with.
Check your web.config file, there should be a line in there that looks like
this:

<compilation debug="true" strict="false" explicit="true"/>

Notice: debug="true"

I have create a new test ASP.NET site. I added one button to the aspx page
and then in the Page_Load and the Button_Click event handlers, I have
written one simple line of code (to have something to set a breakpoint on).

I set 2 breakpoints (one inside of each handler) and press F5.

Because my web.config file was not set up for debugging (the default), I was
prompted to see if I wanted it to be automatically turned on for me, I
answered "Ok".

That's it, the application runs and then stops at my breakpoint. With the
exception of web.config (which didn't exist in VB 6.0). The procedure is
exactly the same as it was in VB 6.0.

I don't know why Start Debugging is greyed out. Does F5 (same thing) do
anything for you? Also, don't use "View In Browser". F5 does the same
thing but with debugging enabled.

Have you changed anything else about the project's settings?
 
A

Arpan

Check your web.config file, there should be a line in there that looks like
this:

<compilation debug="true" strict="false" explicit="true"/>

Notice: debug="true"

Scott, this is how my web.config file looks:

<configuration
xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<appSettings>
<add key="DSN"
value="Server=(local);Database=MyDB;UID=MyUID;PWD=MyPWD"/>
</appSettings>
<system.web>
<compilation debug="true" strict="false" explicit="true"/>
</system.web>
</configuration>

But still when I set a breakpoint on any line in an ASPX file, "Start
Debugging" still remains disabled! Pressing F5 in the VWD IDE just
doesn't do anything; nothing happens. Why isn't VWD still not letting
me debug ASPX pages?

Note that all my ASPX pages reside in the C:\Inetpub\wwwroot\ASPX
directory. web.config exists in C:\Inetpub\wwwroot as well as in
C:\Inetpub\wwwroot\ASPX.

Like yours, even my web.config was not set up for debugging but when I
pressed F5 (which always remains disabled), VWD didn't (& still
doesn't) prompt me to whether I want to enable debugging or not!

Please help me out with this debugging problem.

Arpan
 
S

Scott M.

I really don't know what to tell you. Debugging is for some reason disabled
in your VWD. I have not heard of F5 and start debugging being greyed out.

I have 2 suggestions. Create a brand new test ASP.NET web application, add
a simple variable declaration (with value assignment) in the Page_Load
event handler, set a breakpoint on it and see if F5 and/or the Start
Debuggin menu item are available.

If not, I would suggest another post here entitled F5 and/or Start Debugging
Don't Work in VWD 2005.

Sorry, good luck. If you do find your answer, please post it here to help
others.

Thanks,

Scott
 
A

Arpan

Scott, could it be because I am viewing my ASPX pages using the VWD
built-in ASP.NET Development Server & not IIS? I don't think
so....just shooting in the dark!

Arpan
 
S

Scott M.

It could be, I use IIS so I can't say for sure, but that is a very distinct
possibility. It could be that that web server is just enough to run pages,
but not enough to support debugging of them.
 
A

Arpan

Scott, I could finally enable the "Start Debugging" button on the
toolbar & under the "Debug" menu!

All I did was clicked "File"--->"Recent Projects" from the menubar (I
save all my ASPX files in the C:\Inetpub\wwwroot\ASPX directory). It
listed just 1 project i.e. http://localhost/ASPX. I just clicked on it.
2 ASPX files existing in the above-mentioned directory opened & to my
surprise, the "Start Debugging" button & menu got enabled. Now by
pressing F5, I am now able to step over each line in the code. Finally
good riddance to bad rubbish :)

I guess the reason why I couldn't debug earlier was because I was
opening ASPX files as single independent files & not as part of a
project which is why the "Start Debugging" button & menu were disabled.
Could that be the cause why VWD wasn't allowing me to debug ASPX pages?

Well, now that I am able to debug, I came across another petty problem
- not a problem - rather a nuisance. Suppose I am working with an ASPX
file named "Hello.aspx" & that's the only file open in VWD currently.
Now when I click the "Start Debugging" button (note that only 1 ASPX
file is open presently), irrespective of the ASPX file I am currently
working on has errors or not, all the ASPX pages residing in the
above-mentioned directory get debugged. As a result, errors existing in
other ASPX pages, though they aren't open in VWD, get clustered in the
Output window & in the Error List window. How do I avoid this so that
VWD debugs only that ASPX page which I am currently working on?

Arpan
 
S

Scott M.

Ohhhh!!! You never mentioned that you weren't working with a full solution
open (which is normally how we work with the IDE). Yes, of course. If you
don't have the full solution open, you don't get to debug the single file
you have.

You should always work by opening a project (solution), rather than
indepenently working with loose files.
 
A

Arpan

Scott, 1 last question on VWD 2005 - as already said, I can now debug
ASPX pages from VWD 2005. Assume that only 1 ASPX file, named
Hello.aspx, is open presently in VWD. Now when I click the "Start
Debugging" button on the toolbar, VWD not only debugs Hello.aspx but
also debugs ALL the ASPX pages residing in C:\Inetpub\wwwroot\ASPX i.e.
all the ASPX files that are part of the project get debugged although
they aren't open in VWD. Now since all the errors get clustered in the
Error List, one has to scroll down the entire list of errors in the
Error List window pane to locate the error, if any, that the currently
open ASPX file (i.e. Hello.aspx) has generated.

Is there anyway by which I can make VWD debug only that page which I am
currently working with & not all the ASPX pages?

Arpan
 
S

Scott M.

Since all the code (server-side) you write gets compiled into one assembly
(.dll), all the code must be compiled when you attempt to run any single
page in the project (using debug mode). The only thing you can do is
right-click on the file(s) that you don't want checked and choose to exclude
them from the project. This would be a temporary thing and you'd need to
include the file(s) back into the project later.
 

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

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top