Several considerations written in .NET WEB Custom Control (original)

xiaoxiao2021-03-06  95

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 properties, if it is the reflection of the child control itself, you can take it directly, the value will be automatically reserved, if you belong to your own defined properties, reserved the status with ViewState

E.g:

///

/// 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-107564.html

New Post(0)