Several precautions for WEB custom controls in .NET (transfer)

xiaoxiao2021-03-06  38

If the Enable property provided by the parent class, it will cause the value in the sub-control to return, ie the state cannot be kept. So it is best to define this class attribute and implement it. When defining the property, if it is the reflection of the sub-control itself, you can take it directly, the value will be automatically reserved, if you belong to your own defined properties, with the viewState reserved, for example:

///

/// text box value TXTMD is a web textbox

///

[Bindable (TRUE),

Category ("APPEARANCE"),

DEFAULTVALUE ("")]

Public String Text

{

get

{

IF (txtmd.text! = ")

Return TXTMD.TEXT;

Else

""; "

}

set

{

TXTMD.TEXT = VALUE;

}

}

Custom attribute: ///

// / Reference entry window width

///

[Bindable (TRUE),

Category ("APPEARANCE"),

DEFAULTVALUE ("50")]

Public int textboxmaxlength

{

get

{

Return ViewState [this.uniqueid "textboxmaxlength"] == NULL? 50: (int) ViewState [this.uniqueid "textboxmaxlength"];

}

set

{

ViewState [this.uniqueID "TextBoxMaxLength"] = Value;

}

}

Note: Plus this.uniqueID is the same attribute when distinguishing between multiple identical controls on the same page.

转载请注明原文地址:https://www.9cbs.com/read-63480.html

New Post(0)