473,490 Members | 2,458 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Override a posted form value

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

Feb 2 '07 #1
6 2256
Is this what you want?

if (!IsPostBack) {
}

Peter

<tm*@grislygrotto.comwrote in message
news:11**********************@a75g2000cwd.googlegr oups.com...
>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

Feb 2 '07 #2
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

Feb 2 '07 #3
you should create the controls in oninit. then by form load the postback
values will be applied, and can be overridden.

-- bruce (sqlwork.com)

tm*@grislygrotto.com wrote:
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
Feb 2 '07 #4
tmb
On Feb 2, 5:30 pm, bruce barker <nos...@nospam.comwrote:
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

Feb 3 '07 #5
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.

--
Teemu Keiski
AspInsider, ASP.NET MVP
http://blogs.aspadvice.com/joteke
http://teemukeiski.net
<tm*@grislygrotto.comwrote in message
news:11**********************@a75g2000cwd.googlegr oups.com...
>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
Feb 4 '07 #6
tmb
On Feb 4, 8:54 am, "Teemu Keiski" <jot...@aspalliance.comwrote:
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

Feb 4 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
5115
by: Kelly Domalik | last post by:
I would like to override the "disabled" property of a hidden field. When disabled is set to "true", it would call a function to disable 2 other text fields on the form. When disabled is set to...
14
12103
by: JPRoot | last post by:
Hi I use the following syntax to have events inherited from base to child classes which works nicely (virtual and override keyword on events). But I am wondering if it is a "supported" way of using...
8
2874
by: JPRoot | last post by:
Hi M. Jeffrey Tan, Just hopping you didn't forget me? :) Thanks JPRoot ----- \"Jeffrey Tan\" wrote: -----
2
1316
by: Mark Essex | last post by:
I am trying to build an interface that requires the developer to use the OVERRIDE option. I looked at abstract classes, but seemed to have a couple of problems: 1. If you do this in a form, it...
18
4805
by: bhavin | last post by:
Hi, Can someone point me to some good best practices kind of documentation on use of events compared to method overriding. Ex. In Windows Forms when should i have an event handler for Paint, and...
3
4218
by: Richard | last post by:
I have a requirement to put a GDI style circle or rectangle border around the selected row of a datagrid/ It will overlap into the row above and below the selected row. Doing this in a the OnPaint...
8
5466
by: bdeviled | last post by:
I am deploying to a web environment that uses load balancing and to insure that sessions persist across servers, the environment uses SQL to manage sessions. The machine.config file determines how...
2
1996
by: Jason Huang | last post by:
Hi, In my C# Windows form MyForm, it has a function MyFunction which is a big function and has lots of codes. I am thinking the override for MyFunction, one MyFunction has a parameter which...
52
3414
by: Jim Langston | last post by:
I wanted to do an operator override for but couldnt' figure out the syntax. I tried this (code that doesn't compile commented out with //: class CMyBitmap { public: CMyBitmap( int Rows, int...
0
6967
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
6847
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7352
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5445
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4875
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4565
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1383
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
618
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
272
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.