Re: ascx added at button click event doesn't carry the value on postback
From: Bob (bobatkpmg_at_yahoo.com)
Date: 03/17/04
- Next message: george d lake: "So, how do I get it to work then....."
- Previous message: Beginner: "Checkbox in Repeaters"
- In reply to: Bill Borg: "RE: ascx added at button click event doesn't carry the value on postback"
- Next in thread: Bill Borg: "Re: ascx added at button click event doesn't carry the value on postback"
- Reply: Bill Borg: "Re: ascx added at button click event doesn't carry the value on postback"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 17 Mar 2004 11:01:29 -0600
Hi Bill, thanks for your reply and suggestions. I ended up doing something
similar to what you said at the end, loading both ascx into the aspx at the
same time but set the Visible property to true or false as appropriate. It
works fine for now but if the issues is expanded to have many ascx controls
in a multiple-step process, loading them all seems pretty heavy.
I just keep thinking there should be a way that the load-process-load next
design can work. It's such a no brainer in Windows app. I'll try some
different events like Prerender to see how it goes.
About your comments on doing event rather than public methods, do you mean
to add my own event in the ascx? What I'm doing right now is for the button
click event handler on the aspx to call the ascx public method. Do you mean
for it to fire a custom-made event in the ascx?
Thanks
Bob
"Bill Borg" <anonymous@discussions.microsoft.com> wrote in message
news:DD07CA6C-01FA-4DE0-ADBF-8EC719959AC1@microsoft.com...
> Hello Bob,
>
> I can't quite tell if this is relevant to your case, but I've been working
on similar such stuff and one thing that's important: The (condensed) steps
in building the page are 1) PageLoad, 2) Fire event handlers for buttons,
grids, etc., and 3) PagePrerender.
>
> In your case, on the first pass the page loads, you add your control, and
the page renders. Now the user is looking at the page with your control and
clicks a button. On the second pass, the page loads again, *then* the click
event is processed. Is it possible that moving your PageLoad logic to
PagePrerender would help?
>
> I don't totally understand all the ins and outs here, but hoping this
might prod an idea. I also know that, as you say, the sequence of what's
added when is very important to viewstate, and I'm just trying to figure it
all out. You might consider at least for starters bypassing the automatic
viewstate and using viewstate or session on your own to store things away
and get them on your own terms. Shouldn't have to do this forever, but imho
viewstate is a bit of a hairy beast to understand because there's so much
going on behind the scenes, and sometimes it's better to do an end run at
least for the moment.
>
> Finally, a user control is great for reusing logic, and if you need it on
more than one page then that's the best way to go (although in that case the
best way to communicate among them is by raising/consuming events, not by
calling public methods). They're also handy if you want to customize them
on disk without having to rebuild the app. But, in your case, I'm not sure
that either of these is important to you. Anyway, have you considered this
scenario: a single page, two panels with your two different sets of input,
only one of which is visible at any one time? It's simpler and easier to
code, and might do what you need.
>
> Bill Borg
>
> ----- Bob wrote: -----
>
> I want to create an aspx page to load different ascx controls to
create a
> wizard like process, that is, the aspx page has a Continue button, on
> initial load, it loads the first ascx control into a placeholder, on
> postback, the page's button click event calls a public method on the
ascx to
> process data, then it removes this ascx, loads the second one, and so
on.
>
> Here's the pseudo code of the aspx:
> void Page_Load(object sender, EventArgs e) {
> if it's not postback - the first time
> load ascx 1 into placeholder
> else - subsequent postback
> load ascx i into placeholder
> (ascx i is ascx 1 on first postback, ascx 2 on second
postback)
>
> void Button_Click(object sender, EventArgs e) {
> if it's the first postback
> call ascx1.ProcessData()
> remove ascx 1 from placeholder
> add ascx 2 to placeholder.
> else
> call ascx2.ProcessData()
>
> The problem is that the controls inside ascx 2 (e.g. textboxes) are
all
> empty at call ascx2.ProcessData() even if user entered data. I
tracked this
> down to the fact that ascx 2 is added to the placeholder in the
Button_CLick
> event, not in Page_load. This probably messes up its viewstate due
to the
> event sequence. However I still think my thinking of loading the
ascx
> controls one by one is a good conceptual design, and wonder if there
is a
> way to make this work.
>
> Thanks
> Bob
>
>
>
- Next message: george d lake: "So, how do I get it to work then....."
- Previous message: Beginner: "Checkbox in Repeaters"
- In reply to: Bill Borg: "RE: ascx added at button click event doesn't carry the value on postback"
- Next in thread: Bill Borg: "Re: ascx added at button click event doesn't carry the value on postback"
- Reply: Bill Borg: "Re: ascx added at button click event doesn't carry the value on postback"
- Messages sorted by: [ date ] [ thread ]