Click here to Skip to main content
15,912,475 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi...

App Type: Web Application
SDE: Visual Studio 2008 Pro Edition
Code: asp.net and c#
Using IE 8

I am having an issue in a web based application that I have written that I might be able to better resolve if I understand the exact steps that unfold when someone clicks a submit button that has an event tied to it's click handler. I can find heaps of details on the Page Life cycle itself and what stage does what however when does the actual code for the event tied to the submit button's click handler happen? Sorry if the next question sounds stupid however does the event fire in the same thread as the page cycle or seperately?
That aside I should clearly describe my actual issue as it might not even be related to this. What I am doing is creating dynamic controls based off the contents of an XML file at Page_Load (during non postback). As I create each dynamic control I add them to a main Panel (which is attached to the main page) and I add each control to an ArrayList Session-Variable (see code below). I then use this Session-Variable in a method that then readds the dynamic controls to the Main Panel during the Page_Load event (during postback).
In the OnClick event attached to the Submit button I then check the state of the controls (please note the controls mainly consist of CheckBox Lists and Radio Button Lists) and display a message using a label depending on the results. This works great in around 90% of cases however 3 specific computers around the office receive an error during a call to FindControl inside the OnClick event handler and if I test by reiterating through all controls (including children) on the page it seems none of the dynamic controls exist at that stage inside the event handler. The problem is specific to those 3 particular machines and will always fail (not intermittent) and no clearing of IE cache, restarting the machine will make it work. We run a Standard Operating Environment so everyone has the same build which is XP (service pack 3) running IE 8.
To make matters even more strange (and this is where I am really at a loss) if I make a copy of the aspx and cs file and change its name and then get the same problem machines to run the copy, it then works fine?? However I am not happy with just leaving it at that as I think this error will raise itself again as i think it may be a timing issue in terms of the event. Also we have tried restarting IIS services on the server hosting the web app.
I haven't added too much of my code as i didn't want to make this post too long winded and thought that any code snippets would simply reiterate what I describe above. If someone thinks my c# code would help let me know and I will send through a few more snippets of how I'm going about this.

Code snippet where I add control to session var
C#
if ((ArrayList)Session["dynamicControlsArray"] == null)
        {
            ArrayList arr = new ArrayList();
            Session["dynamicControlsArray"] = arr;
        }
        ((ArrayList)Session["dynamicControlsArray"]).Add([nameOfControl]);


Code snippet of Page_load event:
C#
protected void Page_Load(object sender, EventArgs e)
   {
       if (IsPostBack)
       {
           ReaddDynamicControls();
           // This method simply iterates through the above stored array and adds each back to the main panel
       }
       else
       {
           Session["dynamicControlsArray"] = null;
           PopulateForm(); // This method opens an XML file and creates radio button and checkbox lists based on the contents of it.

       }


Thanks for taking the time to read this and have a great day!
Danny
Posted

1 solution

after page_load and page_loadcomplete
 
Share this answer
 
Comments
Danny Mosquito 19-Jan-12 2:14am    
Hi Jephunneh... Thanks heaps for your quick response... In a way I was hoping that wouldn't be the case as it means something else is causing my issues as my dynamic controls should well and truly be readded to the main panel by the time the OnClick event fires. I am going to try and add some logging to my app to see if the Session variable is maintaining its data after the postback.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900