473,324 Members | 2,239 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Why can't I get the value when I disable a control?

I have code that will set a drop-down list value to "xyz" and the .Enabled
property to False. However, when I do that I can no longer retrieve the
value "xyz" upon postback. It is as if I set the .Visible property to False
as well and the control wasn't rendered, but I did not. If you View Source
of the rendered HTML, you can see that the control is indeed still intact
(everything is the same except the disabled argument is set to "disabled").

Why can't I get the value when I disable a control?

Thanks,
Mike
Nov 17 '05 #1
6 1270
That is by design.

What you can do however is to set a hidden form field to the value of the selectbox just before you disable it, and retrieve that instead.

Hope that helps,
Wim Hollebrandse
http://www.wimdows.net
http://www.wimdows.com

---
Posted using Wimdows.net Newsgroups - http://www.wimdows.net/newsgroups/
Nov 17 '05 #2
Hi Wim,

Is it by design for version 1.1? I am using 1.0 and this is not happening.
Thanks,

Lenny

"Wim Hollebrandse" <wim@-NOSPAM-wimdows.net> wrote in message
news:Ob**************@TK2MSFTNGP11.phx.gbl...
That is by design.

What you can do however is to set a hidden form field to the value of the selectbox just before you disable it, and retrieve that instead.
Hope that helps,
Wim Hollebrandse
http://www.wimdows.net
http://www.wimdows.com

---
Posted using Wimdows.net Newsgroups - http://www.wimdows.net/newsgroups/

Nov 17 '05 #3
Thanks Wim,
Good idea,
Mike

"Wim Hollebrandse" <wim@-NOSPAM-wimdows.net> wrote in message
news:Ob**************@TK2MSFTNGP11.phx.gbl...
That is by design.

What you can do however is to set a hidden form field to the value of the selectbox just before you disable it, and retrieve that instead.
Hope that helps,
Wim Hollebrandse
http://www.wimdows.net
http://www.wimdows.com

---
Posted using Wimdows.net Newsgroups - http://www.wimdows.net/newsgroups/

Nov 17 '05 #4
In article <ed**************@tk2msftngp13.phx.gbl>, L. L. wrote:

Is it by design for version 1.1? I am using 1.0 and this is not happening.


It's by design in the HTML spec. ASP.NET versions have nothing to do
with it. Browsers aren't supposed to submit the values of disabled
controls.

Nov 17 '05 #5
It's as per the W3C HTML standards.

http://www.w3.org/TR/REC-html40/inte...ssful-controls

I am pretty sure it is the same for version 1.0 as its a browser/HTML issue and does not really have any bearing on the serverside controls (as long as they render the disabled attribute).

Cheers,
Wim
http://www.wimdows.net
http://www.wimdows.com

---
Posted using Wimdows.net Newsgroups - http://www.wimdows.net/newsgroups/
Nov 17 '05 #6
Mike,

For a dropdown, you don't set the value like
DropDownList1.SelectedItem.Value = "xyz". Instead, you do this
DropDownList1.SelecteIndex = i; //i is the index of value "xyz" in the
dropdown, starting from 0.

Make sure only set it once in the Page_Load event like,

if(!Page.IsPostBack)

{

DropDownList1.SelectedIndex = 1;

DropDownList1.Enabled = false;//you can still get the value on postaback

DropDownList1.Visible = false;//you can still get the value on postaback

}

In the postback, I am sure you can get the value through code like,

string ddlvalue = DropDownList1.SelectedItem.Value;

It doesn't matter the ddl is enabled or not. The ddl can even be invisible.

L.L.

"Mike Hnatt" <do**@gladstone-inc.com> wrote in message
news:vp************@corp.supernews.com...
I have code that will set a drop-down list value to "xyz" and the .Enabled
property to False. However, when I do that I can no longer retrieve the
value "xyz" upon postback. It is as if I set the .Visible property to False as well and the control wasn't rendered, but I did not. If you View Source of the rendered HTML, you can see that the control is indeed still intact
(everything is the same except the disabled argument is set to "disabled").
Why can't I get the value when I disable a control?

Thanks,
Mike

Nov 17 '05 #7

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

Similar topics

2
by: Fie Fie Niles | last post by:
This one XP machine (with IE 6) is having a problem viewing any ActiveX controls (created on VB6) on the Internet Explorer browser. I put the same ActiveX control in a VB program, and when I run...
1
by: Hardy Wang | last post by:
Guys, I have a web form with some <Asp:TextBox> controls, on some condition, I need to trigger a client side JavaScript to clean all values of these boxes, like below: function DisableForm() {...
4
by: Ken Varn | last post by:
I am trying to cut down the amount ViewState data that is passed to the client browser. I have a number of Web Server Controls on my page, but I am confused as to when ViewState can be disabled to...
0
by: Robert Ladd | last post by:
Hi, I'm trying to disable the asp.net calendar control from a javascript function, but it doesn't disable the doPostBack. To simplify the situation, assume a page with 4 controls. A...
13
by: Rich | last post by:
Hello, So I would like to disable a textbox on a vb.net form without the text getting grayed out. In vb6 I could place a textbox control on a frame control and disable the frame leaving the...
6
by: | last post by:
hi, how to disable the controls in page? thanks For each myControl in Page.Controls 'want to disable myControl? Next
4
by: Joseph Geretz | last post by:
We use a Soap Header to pass a token class (m_Token) back and forth with authenticated session information. Given the following implementation for our Logout method, I vastly prefer to simply code...
8
by: freeskier | last post by:
I have been using the following code to cycle through a subform and disable all textboxes on a form. If a textbox on the form has the focus when this is run I get error "can't disable a control when...
4
by: mark4asp | last post by:
I have an element, report which contains tags which have been transformed. E.g. <pis &lt;p&gt <myXml> <report>This text has html tags in it.&lt;p&gt which but <has been changed to &lt;&gt</report>...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.