Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Disable controls/elements based on form load

Status
Not open for further replies.

GoTerps88

Programmer
Apr 30, 2007
174
US
I need to enable/disable controls or make div elements visible/invisible as the form loads based on data stored in a database.

I'm assuming I would need to incorporate javascript or vbscript into this to make it work. I'm able to get the data I need, I just need to determine the right event to use to modify html elements and controls.

There doesn't seem to be a form load event I can use, but there is a body load event. But doesn't that occur before any elements are drawn on the page?

Thanks in advance...
 
The usual situation in ASP when building pages based on data stored in a database is that the ASP script sends line after line of HTML in a stream to the browser which requested the "page".

Furthermore the ASP script will retrieve data from the database before it starts building the HTML stream. Therefore the ASP script has the data it needs to determine whether to build the div elements or skip them.

That all happens on the web server before anything is sent to the browser. The browser is wher Javascipt runs; and where visible/invisible property of div elements may be controlled.

In other words, dont build the div elements if you dont wish to display them.

It has nothing to do with window events which occur in the browser. But since you asked, an onload event in a body element fires after the page is completely loaded including all images.

I am not aware of an onload event for a form element or other DOM elements, but you might look at it. There is a link to a DOM reference in thread216-1369949
 
So another words I'm building the HTML elements on the fly based on conditional statements in the server-side code?

According to what you are saying, no matter where I place the ASP code, it's going to run BEFORE the HTML is rendered?

That helps me understand the process a bit more.
 
So another words I'm building the HTML elements on the fly based on conditional statements in the server-side code?

According to what you are saying, no matter where I place the ASP code, it's going to run BEFORE the HTML is rendered?

Those statements are both spot on.

Based on your situation, you can just pull the data you need from the database and disable/enable make visible/invisible what you need. I'll show you a setup situation for making something visible/invisible based on an ASP value.

Code:
CSS
div.invisible {
   visibility:hidden;
}

div.shown {
   visibility:visible;
}


ASP
<%
//Assume databaseVar is a variable you pulled from your database
dim databaseVar
set databaseVar = 0
%>
<div class=<%=IIf(databaseVar = 0, 'invisible', 'visible')%>>
content.....
</div>

*Note: I'm not 100% sure my ternary operator works (IIf). I ususally code ASP with JavaScript.







[monkey][snake] <.
 
Monk, that's an interesting concept there just haven't tried it yet.

I guess I had been looking for form events because I am accustomed to ASP.NET. But at work we are maintaining some ASP applications as well.

A lot of ASP.NET developers exhibit a loathing for ASP, but it's not that bad to work with. In the end it renders as html either way right?
 
Im just learning ASP.NET 2.0 after many years with ASP. As part of this I am also learning Visual Studio 2005. I am nearly finished in the WROX Beginning ... with C#.

My reaction, I would say, is not so much loathing, as incredulous amazement at how something so straightforward as making web pages could be transformed into something so overwhelmingly complex. And presented with phrases like "you can easily", and "just drag-and-drop". Orwellian Newspeak if ever there was.

It is quite interesting to see the division of web pages into Web Forms and whats the other one Simple Web page. And the idea of the partial class with the HTML-generating .NET widgets in one part and the "event" handlers in the code-behind part. As an idea it is interesting, as a development platform it is wack. But that is just one late-adopters Luddite opinion.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top