ASP Life Cycle Problem

  • Thread starter Thread starter Michael Johnson Jr.
  • Start date Start date
M

Michael Johnson Jr.

The problem is the following pseudo code causes you need to click buttons
twice to get event.

This is notable via debugging and single stepping.

I can't seem to quite figure out how to do events in ASP where they need to
rerender the page.

I been banging my head on this for 4 days now.




Page_Load

If (Page.PostBack)

Session["currentDir"] = App["rootDir"]

updateTable(Session["currentDir"]

updateTable(currentDir)

string[] dirs = Directory.GetDirectories(currentDir)

foreach dir in dirs

button.Attribs["dir"];

button.Click = myButton_click

tCell1.Controls.Add(button)

Tabl1.Rows.Add(tRow)

myButton_click

Session["currentDir"] = button.Attribs["dir"]

// previously I used this statement but I found it caused the
event to fire twice (cause it wouldn't work period if I didn't have it run
again in page load

// updateTable(button.Attribs["dir"]
 
I have read that before, someone wrote an article that was very similar to
that.

Problem is I still don't understand what I need to do.

I tried 20+ different ways of doing things and I can't get anywhere, it is
getting very fusterating to spend 5 days trying to do something so simple.

It all works except for this problem which is causing other problems.

I am basically using the Page_Load event to iterate data, populate table web
contol, which generates buttons on each row and links an event handler to
it. But the event handler won't fire unless this method gets called on page
load even on post back, so that causes the data to reset itself and thus
nullifies the point of the button. (It does work, but when you go down more
than 1 level it fails). If i use a session variable on the button, then I
got to click the button twice (cause the page load generates the page with
the last settings, then the event button changes the default dir, then need
another page load to run the new settings).

When I do a debug on it, this is what I see.

Debug Start.


Page Load
UpdateTable(Session VAR) (Called from Page_Load)
<User Clicks Button>
Page_Load()
UpdateTable(Session VAR) (Called from Page_Load)
Button_Click Event() (Sets session variable)

What this does, is causes it to require a second button click (or some sort
of event to cause the program to do another page refresh with the new
session var since the button click isn't handled before the page load).


Kevin Spencer said:
The following link may be useful to you:

http://msdn.microsoft.com/library/d...guide/html/cpconControlExecutionLifecycle.asp

--
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

Michael Johnson Jr. said:
The problem is the following pseudo code causes you need to click buttons
twice to get event.

This is notable via debugging and single stepping.

I can't seem to quite figure out how to do events in ASP where they need to
rerender the page.

I been banging my head on this for 4 days now.




Page_Load

If (Page.PostBack)

Session["currentDir"] = App["rootDir"]

updateTable(Session["currentDir"]

updateTable(currentDir)

string[] dirs = Directory.GetDirectories(currentDir)

foreach dir in dirs

button.Attribs["dir"];

button.Click = myButton_click

tCell1.Controls.Add(button)

Tabl1.Rows.Add(tRow)

myButton_click

Session["currentDir"] = button.Attribs["dir"]

// previously I used this statement but I found it caused the
event to fire twice (cause it wouldn't work period if I didn't have it run
again in page load

// updateTable(button.Attribs["dir"]
 
Michael,

Put your code to populate the table web control into a subroutine. Call that
subroutine in the page load to populate the table with the current session.
Then call the subroutine again to refresh at the end of the button click
event.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche


Michael Johnson Jr. said:
I have read that before, someone wrote an article that was very similar to
that.

Problem is I still don't understand what I need to do.

I tried 20+ different ways of doing things and I can't get anywhere, it is
getting very fusterating to spend 5 days trying to do something so simple.

It all works except for this problem which is causing other problems.

I am basically using the Page_Load event to iterate data, populate table web
contol, which generates buttons on each row and links an event handler to
it. But the event handler won't fire unless this method gets called on page
load even on post back, so that causes the data to reset itself and thus
nullifies the point of the button. (It does work, but when you go down more
than 1 level it fails). If i use a session variable on the button, then I
got to click the button twice (cause the page load generates the page with
the last settings, then the event button changes the default dir, then need
another page load to run the new settings).

When I do a debug on it, this is what I see.

Debug Start.


Page Load
UpdateTable(Session VAR) (Called from Page_Load)
<User Clicks Button>
Page_Load()
UpdateTable(Session VAR) (Called from Page_Load)
Button_Click Event() (Sets session variable)

What this does, is causes it to require a second button click (or some sort
of event to cause the program to do another page refresh with the new
session var since the button click isn't handled before the page load).


Kevin Spencer said:
The following link may be useful to you:
http://msdn.microsoft.com/library/d...guide/html/cpconControlExecutionLifecycle.asp
--
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

Michael Johnson Jr. said:
The problem is the following pseudo code causes you need to click buttons
twice to get event.

This is notable via debugging and single stepping.

I can't seem to quite figure out how to do events in ASP where they
need
to
rerender the page.

I been banging my head on this for 4 days now.




Page_Load

If (Page.PostBack)

Session["currentDir"] = App["rootDir"]

updateTable(Session["currentDir"]

updateTable(currentDir)

string[] dirs = Directory.GetDirectories(currentDir)

foreach dir in dirs

button.Attribs["dir"];

button.Click = myButton_click

tCell1.Controls.Add(button)

Tabl1.Rows.Add(tRow)

myButton_click

Session["currentDir"] = button.Attribs["dir"]

// previously I used this statement but I found it caused the
event to fire twice (cause it wouldn't work period if I didn't have it run
again in page load

// updateTable(button.Attribs["dir"]
 
Back
Top