469,945 Members | 2,294 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,945 developers. It's quick & easy.

ASP Life Cycle Problem



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"]
Nov 18 '05 #1
3 1389
The following link may be useful to you:

http://msdn.microsoft.com/library/de...nLifecycle.asp

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

"Michael Johnson Jr." <me@isp.com> wrote in message
news:OO**************@TK2MSFTNGP09.phx.gbl...


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"]

Nov 18 '05 #2
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" <ke***@takempis.com> wrote in message
news:ub**************@TK2MSFTNGP10.phx.gbl...
The following link may be useful to you:

http://msdn.microsoft.com/library/de...nLifecycle.asp
--
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"Michael Johnson Jr." <me@isp.com> wrote in message
news:OO**************@TK2MSFTNGP09.phx.gbl...


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"]


Nov 18 '05 #3
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." <me@isp.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
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" <ke***@takempis.com> wrote in message
news:ub**************@TK2MSFTNGP10.phx.gbl...
The following link may be useful to you:

http://msdn.microsoft.com/library/de...nLifecycle.asp

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

"Michael Johnson Jr." <me@isp.com> wrote in message
news:OO**************@TK2MSFTNGP09.phx.gbl...


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"]



Nov 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by prem | last post: by
6 posts views Thread by jim | last post: by
16 posts views Thread by bharathi.vempati | last post: by
3 posts views Thread by Griff | last post: by
1 post views Thread by =?Utf-8?B?U2FtZWVrc2hh?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.