The Diable property for HTML server control does not work

  • Thread starter Thread starter Tony Johansson
  • Start date Start date
T

Tony Johansson

Hello!

Below I have the aspx page and the code behind file.
This question is just for learning.
In the code behind file I have set the HTML server control div property
Disable to true in this way
to DIV1.Disabled = true;
but it doesn't not have any effect. I thought it should disable the working
for this HTML server control.
So my question is why does it still work when I have set the Disable
property to true

//aspx page here
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div id="DIV1" runat="server" style="font-family: Verdana; font-size:
large; background-color: #FFFF00; position: absolute;">
</div>
</form>
</body>
</html>

//Code behind file here
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
DIV1.Disabled = true;
//Put user code to initialize the page here
DIV1.InnerHtml = "<h3>" + "The select box's style collection
contains:" + "</h3>";
//Create an object to move through style collection of the box DIV1
IEnumerator keys = DIV1.Style.Keys.GetEnumerator();
//Move to the next item and write its values untill reach the last
item

while (keys.MoveNext())
{
string key = (string)keys.Current;
DIV1.InnerHtml += key + "=" + DIV1.Style[key] + "<br>";
}
}
}
//Tony
 
Hello!

Below I have the aspx page and the code behind file.
This question is just for learning.
In the code behind file I have set the HTML server control div property
Disable to true in this way
to DIV1.Disabled = true;
but it doesn't not have any effect. I thought it should disable the working
for this HTML server control.
So my question is why does it still work when I have set the Disable
property to true

//aspx page here
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div id="DIV1" runat="server" style="font-family: Verdana; font-size:
large; background-color: #FFFF00; position: absolute;">
</div>
</form>
</body>
</html>

//Code behind file here
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
DIV1.Disabled = true;
//Put user code to initialize the page here
DIV1.InnerHtml = "<h3>" + "The select box's style collection
contains:" + "</h3>";
//Create an object to move through style collection of the box DIV1
IEnumerator keys = DIV1.Style.Keys.GetEnumerator();
//Move to the next item and write its values untill reach the last
item

while (keys.MoveNext())
{
string key = (string)keys.Current;
DIV1.InnerHtml += key + "=" + DIV1.Style[key] + "<br>";
}
}
}

http://msdn.microsoft.com/en-us/library/system.web.ui.htmlcontrols.htmlcontrol.disabled.aspx
says:

In the browser, a disabled element or control is read-only, with the
following added restrictions: its value is not submitted with the form,
the element or control cannot receive focus, and the element or control
is skipped when navigating the document by tabbing.

Arne
 
Back
Top