Page 1 of 1

Hooking Custom Class into Able objects

Posted: Thu Jan 08, 2009 6:12 pm
by jmestep
I'm trying to extend some of the Able objects with other datafields from additional tables I have added to the database. For example, I have a CustomWebpageType table with two fields-- a webpageId and a webpageType. I've followed the pattern on the Wiki for a data access layer and I have over 2000 lines of code written in a class for all these new objects but I'm stumped now. Every time I get to this point, I can't go further.
In this instance, I'm trying to add the data in the webpageType field into a text box on the edit webpage page in the admin.
I've put the dll from the custom class into the bin folder of the website
I've put in a using Custom.Objects; on the EditWebpage.aspx.cs

In the code, I've added in my code like this:

Code: Select all

 private int _WebpageId;
    private Webpage _Webpage;
    private WebpageType _WebpageType;
protected void Page_Init(object sender, EventArgs e)
    {
        _WebpageId = AlwaysConvert.ToInt(Request.QueryString["WebpageId"]);
        _Webpage = WebpageDataSource.Load(_WebpageId);
       _WebpageType = WebpageTypeDataSource.Load(_WebpageId);
 
        CancelButton.NavigateUrl = "Browse.aspx?CategoryId=" + PageHelper.GetCategoryId().ToString();
     
        _WebpageType = WebpageTypeDataSource.Load(_WebpageId);
This all colors fine with intellisense and the project builds. (The Custom Object class built OK also)

Then down in the code for if (!Page.IsPostBack)

I have added to the listing
TextBoxType.Text = _WebpageType.ToString();

I always get a System.StackOverflowException was unhandled error and can't figure out why or how to debug it.

Where would I start to figure out what the problem is? It's been 2 1/2 days typing all this code and my brain is fried.

Thanks

Re: Hooking Custom Class into Able objects

Posted: Fri Jan 09, 2009 8:05 am
by mazhar
Make sure you do not have an infinite loop or infinite recursion some where in code.

Re: Hooking Custom Class into Able objects

Posted: Fri Jan 09, 2009 10:09 am
by nickc
can't figure out why or how to debug it
Dumb questions maybe...
- a breakpoint set at the top of Page_Init doesn't get hit?
- Is your class in App_Code or a separate dll?

Re: Hooking Custom Class into Able objects

Posted: Fri Jan 09, 2009 10:58 am
by AbleMods
Run it in debugger mode and the stack overflow should trigger you to where the call stack is getting overwhelmed. Most likely the issue is a call inside your class is calling another part of the same class which someone calls the original function and creates an infinite loop.

Put a breakpoint on the first line in Page_Init (or Page_Load) and step line by line until you're into your new class. Then start watching carefully line by line - you should see the debugger never leave your new class code. In other words, somehow a loop has formed and the stack eventually overflows.

Re: Hooking Custom Class into Able objects

Posted: Fri Jan 09, 2009 12:06 pm
by jmestep
Thanks, guys I'll try that. I wasn't even sure how to run with debugger.
The DAL code is in a class library that I have copied to the bin folder of the site. If I can't get it de-bugging, I think I'll copy the DAL code for just one of the objects into the codebehind for an edit page and see what I get there. I've got one class for a table with only two fields, so I'll try that one first.

Re: Hooking Custom Class into Able objects

Posted: Fri Jan 09, 2009 12:11 pm
by mazhar
put both the class library project and website within single solution. Mark the website project as start up project and then run the project in debug mode. Now it will let you debug the source code within class library as well.

Re: Hooking Custom Class into Able objects

Posted: Fri Jan 09, 2009 12:13 pm
by AbleMods
Debugger is pretty intelligent. When I'm running two VS instances, I can put breakpoints in one instance and it'll catch it when the code executes in the DLL of the other instance.

Re: Hooking Custom Class into Able objects

Posted: Fri Jan 09, 2009 12:34 pm
by jmestep
It worked, it worked, it worked!!!!!!!!!!!!
I was using a Load method that needed two arguments instead of a LoadForProduct that only took one.

Thanks so much!

Re: Hooking Custom Class into Able objects

Posted: Fri Jan 09, 2009 12:38 pm
by AbleMods
Odd.

Intellisense should have picked that up. Although if you're coding in C-Sharp, I've seen it delay intellisense until after you've saved the file. VB doesn't seem to have that issue so I dunno if it's a setting in my VS setup or what.

Grats on getting it debugged though ;)

Re: Hooking Custom Class into Able objects

Posted: Fri Jan 09, 2009 1:07 pm
by nickc
You VB coders and your fancy background compiling. Real little girls wait 3 minutes for their Able C# website solution to build :)

Re: Hooking Custom Class into Able objects

Posted: Fri Jan 09, 2009 4:00 pm
by jmestep
Well, I'm on to step 2. I can pull from the database, but am having trouble saving back. No error- just nothing happens. I've using the Save()method similar to the Affiliate code on the wiki and calling it from a Finish button on a supplemental page that has had the productid sent to it and it includes all the new fields. The table has an identity field for the key and the productid is a foreign key. On the finish button, I've picked up all the data from the text input fields.
Is there something else I would need to do or a different type of Save method?

Thanks

Re: Hooking Custom Class into Able objects

Posted: Fri Jan 09, 2009 5:31 pm
by AbleMods
Tough to troubleshoot when it's not throwing any exceptions at all. Make sure you have the web.config set so that it doesn't hide errors.

Some things to try:
1. Build a simple ASPX page and use the Page_Load() to test writing a single record. You should be able to populate the required properties and initiate a .Save() that way. Much faster to test and eliminates your user-interface code as culprit. Also helps establish the class itself is working or not.

2. Use the SQL logger to see what SQL command is being sent to the server during .Save(). Then copy/paste that into a SQL command window and execute it - see if SQL itself will throw any errors.

3. Breakpoint the .ExecuteNonQuery() in your .Save() method and see what the result variable returned is. It should be a 1 to indicate 1 record was affected.

4. Check your .IsDirty() logic. If the IsDirty property isn't being set within the individual public properties, the .Save() will do nothing. Might help to breakpoint the .Save() and look at the value of IsDirty() to make sure it's set to True.

Re: Hooking Custom Class into Able objects

Posted: Mon Jan 12, 2009 7:29 am
by jmestep
Thanks for the help on this. I didn't have to do any debugging in Able5-- I just threw in some response.write() and figured it out. I'm working with it on a product edit which is on a separate page like the product templates in the admin. I'll try this on a category edit where the new fields are on the same page as the Able fields.

Re: Hooking Custom Class into Able objects

Posted: Mon Jan 12, 2009 9:44 am
by afm
jmestep wrote:I didn't have to do any debugging in Able5-- I just threw in some response.write() and figured it out.
That is often the most effective debugging technique.

Re: Hooking Custom Class into Able objects

Posted: Mon Jan 12, 2009 4:41 pm
by jmestep
Now I've got it to save edited data if the Able category has data already entered into the parallel table, which has an autonumber id and a foreign key which is the Able categoryId. (Merchant insists on the autonumber field). I think what I have to do is create a new parallel object when the edit category page needs to save form data back into it for a category that doesn't have an entry already in the parallel table. Someone told me he thought it was because I couldn't have a composite key made up of an autonumber field and a non-autonumber field, which I don't believe is the right info.
Anyway, I need to create the new object, then save the parallel data into that table.
Since I'm following the DAL coding pattern from Able, how/where can I pull an identity field for a new object into the edit category page?
Thanks

Re: Hooking Custom Class into Able objects

Posted: Mon Jan 12, 2009 5:34 pm
by jmestep
I got the code to work for a new parallel object. I created a new object if the object was null, picked up the category id for the page, saved, then did a response.redirect back and the code works fine for new and existing objects.