Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 5th, 2007, 01:44 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Also what is CWebPage? I assume this is a custom class you have overridding some functionality of the System.Web.UI.Page class?

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
Technical Editor for:
Professional Search Engine Optimization with ASP.NET

Professional IIS 7 and ASP.NET Integrated Programming

================================================== =========
 
Old September 5th, 2007, 01:47 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Actually, "An error has occurred" generic error is not typical of .NET you should at least be getting the StackTrace?? In your web.config do you have this attribute: <customErrors mode="Off"/> ??

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
Technical Editor for:
Professional Search Engine Optimization with ASP.NET

Professional IIS 7 and ASP.NET Integrated Programming

================================================== =========
 
Old September 5th, 2007, 01:48 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Quote:
quote:First, no, you can not have t[w]o page load events regardless of where they appear.
That's not true. You can have many Load handlers. Try this:

ASPX
Code:
<%@ Page Language="VB" ... AutoEventWireup="True"
CodeFile="Default.aspx.vb" ....%>
<script type="text/VB" runat="server">
  Protected Sub Page_Load(ByVal sender As Object, _
              ByVal e As System.EventArgs)
    Label1.Text += "From Load ASPX<br />"
  End Sub
</script>
<asp:Label ID="Label1" runat="server" Text=""></asp:Label>
followed by this code behind:
Code Behind
Code:
Protected Sub Page_Load1(ByVal sender As Object, _
        ByVal e As System.EventArgs) Handles Me.Load
  Label1.Text += "From Load 1<br />"
End Sub
Protected Sub Page_Load2(ByVal sender As Object, _
        ByVal e As System.EventArgs) Handles Me.Load
  Label1.Text += "From Load 2<br />"
End Sub
Protected Sub Page_Load3(ByVal sender As Object, _
        ByVal e As System.EventArgs) Handles Me.Load
  Label1.Text += "From Load 3<br />"
End Sub
If you run this, you'll see that all four methods get fired, albeit in a somewhat unpredictable order.

Now, whether this is a smart thing to do from a maintainability point of view is of course something completely different. I am sure that most people won't like this design.... ;)

Imar

---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
 
Old September 5th, 2007, 01:56 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Ahh yes and Imar proves me wrong ;] I guess my rationale for my comment was that it seems unnecssary to have more than one method handle the same event, I can't think of a good reason to justify that sort of design.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
Technical Editor for:
Professional Search Engine Optimization with ASP.NET

Professional IIS 7 and ASP.NET Integrated Programming

================================================== =========
 
Old September 5th, 2007, 02:02 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

I couldn't agree more. One handler for one event is usually more than enough. More handlers just make your code so much harder to read and understand. Additionally, since you can't really predict order and behavior, you may end up with subtle bugs....

Imar

---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
 
Old September 5th, 2007, 02:04 PM
Authorized User
 
Join Date: Sep 2007
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

dparsons-

Yes, CWebPage is a massive beast of a class that modifies System.Web.UI.Page

In my web.config, customErrors was set to On, but there was a page redirect attribute. Taking that out revealed that the actual error I am receiving is this:

The following error has occurred:

Class CustSignIn Error=Object reference not set to an instance of an object.


Although as far as I can tell, everything is declared explicitly now.

I think I'll give Imar's suggestion a try and see what happens...

 
Old September 5th, 2007, 02:08 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

If by "giv[ing] Imar's suggestion a try and see what happens..." you mean implementing two Page_Load handlers, you misunderstood me. I am not recommending to do that at all. I only showed that it was possible, not that it's a good or clean solution.

If you have the need for this, you may have other problems that you may need to fix instead....

Imar

---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
 
Old September 5th, 2007, 02:08 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

mmm.. make one more try.. surround your database code with a try catch to see if the error comes from there..
Maybe you are not opening the database or something like this???

if you comment that code the page works ok??

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
 
Old September 5th, 2007, 02:34 PM
Authorized User
 
Join Date: Sep 2007
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for at least trying to help me, by the way. It is very much appreciated.

Yes, if I comment out those lines in the Codebehind and reinsert this little block back into the aspx file, it works perfectly:
Code:
<script type="text/vb" runat="server">

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim dbconn As New SqlConnection( "server=server.net;uid=username;pwd=password;database=test_storefrontdb" )        
        dbconn.Open()
        Dim dbcomm As New SqlCommand( "SELECT * FROM Products", dbconn )
        Dim dbread As SqlDataReader = dbcomm.ExecuteReader()
        FeaturedItems.DataSource = dbread
        FeaturedItems.DataBind()
        dbread.Close()
        dbconn.Close()

    End Sub

</script>
The unfortunate problem with that is that then the login function which runs from the Runbehind's Page_Load() doesn't work anymore. I really only want to do two things on the page: Provide login functionality and pull up a list of items from a database. If I put the same block of code in the Codebehind, for some reason it just doesn't want to work. Am I missing something obvious? I didn't foresee this being such a complicated thing.

Thanks,

blu

 
Old September 5th, 2007, 02:38 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

can you try put it back in the code behind file and surround it with a try catch to see which error did it throw??

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========





Similar Threads
Thread Thread Starter Forum Replies Last Post
simple report and crystal report in vb.net saket123 .NET Framework 2.0 0 August 13th, 2008 06:55 AM
Indian Rs Format simple Function for vb.net s.karthik General .NET 0 March 24th, 2008 06:27 AM
MSSQL 2005 and MSSQL 2000 tiredcat Visual Basic 2005 Basics 0 April 9th, 2007 12:56 AM
Simple ASP.NET message box with VB janicen General .NET 1 February 24th, 2005 03:31 AM
VB MSSQL database REmote connectivity srichary Pro VB Databases 0 November 28th, 2004 06:33 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.