Override a posted form value

T

tmb

I have a page with many dynamically created HtmlSelect controls which
i create in the Page_Load function. Sometimes upon a post i need to
change the selected items in some of the controls depending on the
settings in other dynamic controls which is completely ok since i
create them myself. However, the problem is that this apparently gets
overridden by the form value that came with the postback. This is not
a setting handled by viewstate so turning off viewstate from the
control doesn't work.

My questions is: How do i override this behaviour? Is there some
function where i should do this or can i somehow manipulate the form
values used (they are read-only normally). Should i delay the creation
of the controls until viewstate and form values have been applied? If
so where do i do that and how?

Any help on this is appreciated.

Regards TMB
 
T

tmb

Is this what you want?
if (!IsPostBack) {

}

No, it is a postback already. So the problem is that i want to change
values for a dynamic control that has values in the form coming in
from the postback. This is what happens:

In form:
Ctrl1.Value = 1, Ctrl2.Value = 1

On postback in Page_Load():
if ( Ctrl1.Value = 1 )
Ctrl2.Value = 2 <-- This action is ignored since the setting of the
value to 1 which was posted is done later in the chain overwriting my
2.

On display:
Ctrl1.Value = 1, Ctrl2.Value = 1

So what i need is a way of telling the control to ignore the posted
value or place the creation of the controls to after the form values
have been applied. Also, note that as mentioned this has nothing to do
with viewstate so setting it to false won't work.

Regards TMB
 
B

bruce barker

you should create the controls in oninit. then by form load the postback
values will be applied, and can be overridden.

-- bruce (sqlwork.com)
 
T

tmb

you should create the controls in oninit. then by form load the postback
values will be applied, and can be overridden.

Thanks on the input, Bruce. However, i'm unclear on how this will help
since the only thing i can see happening is that i create the controls
earlier in the process, ie in oninit instead of page_load and the form
values seems to be applied after page_load since they override my
settings done in page_load. Or do you mean if the control exists in
oninit and the values are set there the form values will not be
applied later?

Regards TMB
 
T

Teemu Keiski

If you use ASP.NET 2.0, you can handle that at LoadComplete event (it
happens after all postback data etc is applied). Only issue is that postback
data is handled right after Load event, so your control instances would need
to exist at Load, if you still expect them to load the postback data
normally, but you can then override things at LoadComplete.

Overriding loading at single control level might need custom control
implementation.
 
T

tmb

If you use ASP.NET 2.0, you can handle that at LoadComplete event (it
happens after all postback data etc is applied). Only issue is that postback
data is handled right after Load event, so your control instances would need
to exist at Load, if you still expect them to load the postback data
normally, but you can then override things at LoadComplete.

Overriding loading at single control level might need custom control
implementation.

Strange, i posted an answer and it said it was posted ok but i don't
see it... Oh well. here goes:

Thanks on the insight, Teemu. I never thought about LoadComplete. But
as you say last in your answer it would be better to override Load for
the separate controls instead as there might be many more controls on
the page which i don't want to sift through every post. I think i will
opt for that solution instead as it seems cleaner and i already handle
everything manually in the application. The code has been converted
from asp/vbscript so it doesn't handle the asp.net mechanisms so well.
I think i have my work cut out for me in this case as i also want to
make it more object oriented.

So thanks everybody for your help and be sure that i'll return with
more questions when i get stuck :D

Regards TMB
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top