Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Accessing HTML controls from the CodeBehind
Message
General information
Forum:
ASP.NET
Category:
Web forms
Miscellaneous
Thread ID:
00925305
Message ID:
00927653
Views:
7
Hi Richard

>>>Since the HTML isn't generated for controls that have their Visible set to False>>>

If you set the control's Visible property to false in the code-behind, then the HTML is never generated for it. If you would like to have the control be generated in the HTML but not visible, then you need to alter the style attribute for the control (from the code-behind). This still makes it hidden from the user but still accessible. Here is an example:
this.chkTaxable.Attributes.Add("style","visibility:hidden;");
>>>>
>>I need to use HTML controls (textbox and/or listbox) and want to hide them so the user can't see them. I was wondering how I can set the values of these controls from my CodeBehind area... I have a WebForm DataGrid and in the SelectedIndexChanged I want to write to these HTML controls.
>>>>
>>
>>Doesn't just 'ControlName.Visible = False' work ?
>>
>>>>
>>Also, How can I have my HTML scripts access my WebForm Controls... when their VISIBLE property is set to FALSE?
>>>>
>>
>>If you set an HTML control's Visible property to .F. then .NET simply doesn't generate the relevant HTML
>>
>>>>
>>And, while I'm at it...
>>
>>I have a JavaScript which I'm using to get the value of a WebForm TextBox Control...
>>How would I change it to access a WebForm ListBox Control?
>>I tried what I thought would be right but it didn't like it.
>>
>>function GetTextBoxValue()
>>{
>>	var oTextBox = document.getElementById("txtReminderTime")
>>	return oTextBox.value
>>}
>>
>>>>
>>That look OK assuming you have the names right - except a couple of semicolons might help. What do you mean 'it didn't like it' ?
>
>I figured out the listbox question. The code I used is...
>
><script language="javascript">
>function GetListBoxValue(MyItem)
>{
>	var oListBox = document.getElementById("ListBoxReminderTimes")
>	return oListBox.options[MyItem].value
>}
></script>
>
>
>Since the HTML isn't generated for controls that have their Visible set to False, I ended up with a listbox that's 1 pixel by 1 pixel... It's a work around, but it worked.
>
>Rick
-----------------------------------------

Cathi Gero, CPA
Prenia Software & Consulting Services
Microsoft C# / .NET MVP
Mere Mortals for .NET MVP
cgero@prenia.com
www.prenia.com
Weblog: blogs.prenia.com/cathi
Previous
Reply
Map
View

Click here to load this message in the networking platform