Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Building Custom Controls EnsureChildControls(); txtPassword.Text = value; } } protected override void CreateChildControls() { txtUserName = new TextBox(); txtUserName.ID = “txtUserName”; this.Controls.Add(txtUserName); txtPassword = new TextBox(); txtPassword.ID = “txtPassword”; txtPassword.TextMode = TextBoxMode.Password; this.Controls.Add(txtPassword); } protected override void RenderContents(HtmlTextWriter writer) { writer.AddStyleAttribute(“float”, “left”); writer.RenderBeginTag(HtmlTextWriterTag.Div); writer.AddStyleAttribute(HtmlTextWriterStyle.Padding, “3px”); writer.RenderBeginTag(HtmlTextWriterTag.Div); writer.AddAttribute(HtmlTextWriterAttribute.For, txtUserName.ClientID); writer.RenderBeginTag(HtmlTextWriterTag.Label); writer.Write(“User Name:”); writer.RenderEndTag(); writer.RenderEndTag(); writer.AddStyleAttribute(HtmlTextWriterStyle.Padding, “3px”); writer.RenderBeginTag(HtmlTextWriterTag.Div);. | 1594 CHAPTER 36 Building Custom Controls EnsureChildControls txtPassword.Text value protected override void CreateChildControls txtUserName new TextBox txtUserName.ID txtUserName this.Controls.Add txtUserName txtPassword new TextBox txtPassword.ID txtPassword txtPassword.TextMode TextBoxMode.Password this.Controls.Add txtPassword protected override void RenderContents HtmlTextWriter writer writer.AddStyleAttribute float left writer.RenderBeginTag HtmlTextWriterTag.Div writer.AddStyleAttribute HtmlTextWriterStyle.Padding 3px writer.RenderBeginTag HtmlTextWriterTag.Div writer.AddAttribute HtmlTextWriterAttribute.For txtUserName.ClientID writer.RenderBeginTag HtmlTextWriterTag.Label writer.Write User Name writer.RenderEndTag writer.RenderEndTag writer.AddStyleAttribute HtmlTextWriterStyle.Padding 3px writer.RenderBeginTag HtmlTextWriterTag.Div writer.AddAttribute HtmlTextWriterAttribute.For txtPassword.ClientID writer.RenderBeginTag HtmlTextWriterTag.Label writer.Write Password writer.RenderEndTag writer.RenderEndTag writer.RenderEndTag writer.AddStyleAttribute float left writer.RenderBeginTag HtmlTextWriterTag.Div writer.AddStyleAttribute HtmlTextWriterStyle.Padding 3px writer.RenderBeginTag HtmlTextWriterTag.Div txtUserName.RenderControl writer writer.RenderEndTag From the Library of Wow eBook Overview of Custom Control Building 1595 writer.AddStyleAttribute HtmlTextWriterStyle.Padding 3px writer.RenderBeginTag HtmlTextWriterTag.Div txtPassword.RenderControl writer writer.RenderEndTag writer.RenderEndTag writer.Write br style clear left protected override HtmlTextWriterTag TagKey get return HtmlTextWriterTag.Div The control in Listing 36.11 works quite nicely in all recent browsers Internet Explorer 6 Firefox Opera 8 without requiring an HTML table for layout see Figure 36.6 . 36 FIGURE 36.6 Performing CSS layout. From the Library of Wow eBook 1596 CHAPTER 36 Building Custom Controls View State and Control State The standard ASP.NET controls retain the values of .