jncraig Posts:79

| | 11/21/2007 11:44 AM |
| John, I'm building a small module, but have encountered a problem: Page_Load executes twice, and that confuses the heck out of my module. If I set AutoEventWireup to false, no events fire when the page is loaded. Quite obviously, I'm missing something key. What is it? | | | |
|
|
|
John Mitchell Posts:3248


| | 11/21/2007 11:53 AM |
| page_load may be firing twice because of a re-direct. If it isn't that then I don't know why it would do that unless maybe you have some kind of Ajax, but then it would probably keep firing. Try using Fiddler to find out if the page is actually getting requested more than once.
You may also want to use the Page.IsPostBack property to only run your code if it is a post-back. | | | |
|
jncraig Posts:79

| | 11/21/2007 12:08 PM |
| I'll try your suggestion regarding Fiddler, which I've never used.
There are no redirects, but there is a read from a WebClient object. Could that cause a problem.
I do use IsPostBack. The problem is, the second time the Page_Load fires after a button click event, the IsPostBack property is false. It's true for the first call.
Thanks! | | | |
|
John Mitchell Posts:3248


| | 11/21/2007 12:17 PM |
| Yes, if the WebClient is calling back into the same page then that will do it.
IsPostBack should be doing the opposite of what you described .. True if a button clicked, False if it is just a GET request (first time). | | | |
|
jncraig Posts:79

| | 11/21/2007 2:41 PM |
| | I'm trying to use Fiddler. It doesn't seem to catch requests to my localhost server (I'm developing/testing with VS and its built-in server). Is there a way to do that? | | | |
|
John Mitchell Posts:3248


| | 11/21/2007 2:47 PM |
| | The way I do it is use the machinename instead of localhost, or go into the HOSTS file at %windir%\system32\drivers\etc and add a domain name that points to 127.0.0.1 | | | |
|
jncraig Posts:79

| | 11/21/2007 3:31 PM |
| When the page is loaded, IsPostBack is true.
I think click a button, and that causes stuff to happen. IsPostBack is true. But when it completes the event handling, there is another Page_Load event that's waiting to be processed, and that one is "new" and has IsPostBack set to false.
I set a breakpoint for the Page_Load handler for my module, and then step through the code that executes
1. Page_Load event for my module 1a. Click Handler for the button that I clicked. ( that doesn't happen when the module is first loaded, because there's no button click) 2. Page_Load event for a control that exists in the module 3. Page_Load for Copyright.asxc 4. Page_Load for Terms.ascx 5. Page_Load for Privacy.ascx 6. Page_Prerender for Default.aspx
After I step past the last line in the above, I get the Default.ascx page shown in my debugger with [html [%=xmlns%] highlighted. If I step again lns%] [%=LanguageCode%] is highlighted. If I click again, I'm back to the Page_Load event for the module, and IsPostBack is now false.
Is there a way to find out when events fire? How do I figure out what is causing the second Page_Load?
| | | |
|
John Mitchell Posts:3248


| | 11/21/2007 3:38 PM |
| That really sounds like a response.redirect after the processing is finished. Respose.redirect will bring you back to the page without Page.IsPostBack being true.
Your code should not break in this case but just "start over".
| | | |
|
jncraig Posts:79

| | 11/21/2007 4:25 PM |
| Now I'm really confused. I've stripped the code down to this in the ascx.cs file:
public partial class TestModule : DotNetNuke.Entities.Modules.PortalModuleBase { protected void Page_Load(object sender, EventArgs e) { } }
I have AutoEventWireup="false" in the ascx file, I still get two page load events. If I set AutoEventWireup="true" then I never get any Page_Load events.
I guess that I should retreat to my original statement that I'm really missing some basic understanding of what's happening. | | | |
|
John Mitchell Posts:3248


| | 11/21/2007 4:32 PM |
| | There is probably a response.redirect in some other control on the page ( DotNetNuke has way too many of them ). If you want to try and debug where it is happening you could put a break point on every response.redirect in the app (get ready to buy a new mouse), or if you have everything compiled for debug you should be able to step into each procedure after your code has executed for the first time. | | | |
|
jncraig Posts:79

| | 11/21/2007 6:09 PM |
| Hmmm ... you are going to LOVE this ...
I changed the page skin to the DNN Blue skin. It works. The skin that I was using on the page uses your Nav Menu. The page is otherwise unoccupied by other modules. So ... can you think of something related to the Nav Menu that might have caused that problem. Or, do you have suggestions as to what might be in my skin? I do have some conditional stuff in the skin. I guess that I could start looking there, too.
This is an interested journey through things happening in the background, too! | | | |
|
jncraig Posts:79

| | 11/26/2007 10:57 AM |
| | I haven't been able to figure out what in the skin is causing this. Any ideas? | | | |
|
John Mitchell Posts:3248


| | 11/26/2007 11:07 AM |
| | I don't know for sure, but I would look for a redirect. My NavMenu doesn't do a redirect, but you could try putting just the NavMenu in the skin that works to narrow it down. | | | |
|