程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> ASP.NET >> 關於ASP.NET >> ASP.NET自定義控件組件開發 第二章 繼承WebControl的自定義控件(二)

ASP.NET自定義控件組件開發 第二章 繼承WebControl的自定義控件(二)

編輯:關於ASP.NET

下面就寫了RenderContent方法,不難,只記住這個方法的職責:顯示最外層標記的內容:

如下:

1 protected override void RenderContents(HtmlTextWriter writer)
  2         {
  3             writer.RenderBeginTag(HtmlTextWriterTag.Tr);
  4             writer.RenderBeginTag(HtmlTextWriterTag.Td);
  5             writer.Write(PaymentMethod);
  6             writer.RenderEndTag();
  7
  8             writer.RenderBeginTag(HtmlTextWriterTag.Td);
  9
 10             writer.AddAttribute(HtmlTextWriterAttribute.Id, PaymentMethodListId);
 11             writer.AddAttribute(HtmlTextWriterAttribute.Name, PaymentMethodListName);
 12             writer.AddStyleAttribute(HtmlTextWriterStyle.Width, "100%");
 13             writer.RenderBeginTag(HtmlTextWriterTag.Select);
 14
 15             writer.AddAttribute(HtmlTextWriterAttribute.Value, "0");
 16             writer.RenderBeginTag(HtmlTextWriterTag.Option);
 17             writer.Write("Master");
 18             writer.RenderEndTag();
 19
 20             writer.AddAttribute(HtmlTextWriterAttribute.Value, "1");
 21             writer.RenderBeginTag(HtmlTextWriterTag.Option);
 22             writer.Write("Visa");
 23             writer.RenderEndTag();
 24
 25             writer.RenderEndTag();
 26
 27             writer.RenderEndTag();
 28             writer.RenderEndTag();
 29 //****************************************************************************
 30             writer.RenderBeginTag(HtmlTextWriterTag.Tr);
 31             writer.RenderBeginTag(HtmlTextWriterTag.Td);
 32             writer.Write(CreditCardNo);
 33             writer.RenderEndTag();
 34
 35             writer.RenderBeginTag(HtmlTextWriterTag.Td);
 36             writer.AddAttribute(HtmlTextWriterAttribute.Id, CreditCardNoTextId);
 37             writer.AddAttribute(HtmlTextWriterAttribute.Name, CreditCardNoTextName);
 38             writer.AddAttribute(HtmlTextWriterAttribute.Type, "text");
 39             writer.RenderBeginTag(HtmlTextWriterTag.Input);
 40             writer.RenderEndTag();
 41
 42             writer.RenderEndTag();
 43             writer.RenderEndTag();
 44 //**************************************************************************************
 45
 46             writer.RenderBeginTag(HtmlTextWriterTag.Tr);
 47             writer.RenderBeginTag(HtmlTextWriterTag.Td);
 48             writer.Write(CardholderName);
 49             writer.RenderEndTag();
 50
 51             writer.RenderBeginTag(HtmlTextWriterTag.Td);
 52             writer.AddAttribute(HtmlTextWriterAttribute.Name, CardholderNameTextName);
 53             writer.AddAttribute(HtmlTextWriterAttribute.Id, CardholderNameTextId);
 54             writer.AddAttribute(HtmlTextWriterAttribute.Type, "text");
 55             writer.RenderBeginTag(HtmlTextWriterTag.Input);
 56             writer.RenderEndTag();
 57
 58             writer.RenderEndTag();
 59             writer.RenderEndTag();
 60 

//***************************************************************************************
 61
 62             writer.RenderBeginTag(HtmlTextWriterTag.Tr);
 63             writer.RenderBeginTag(HtmlTextWriterTag.Td);
 64             writer.Write(ExpirationDate);
 65             writer.RenderEndTag();
 66
 67             writer.RenderBeginTag(HtmlTextWriterTag.Td);
 68             writer.AddAttribute(HtmlTextWriterAttribute.Name, MonthListName);
 69             writer.AddAttribute(HtmlTextWriterAttribute.Id, MonthListId);
 70             writer.RenderBeginTag(HtmlTextWriterTag.Select);
 71
 72             for (int month = 1; month < 13; month++)
 73             {
 74                 writer.AddAttribute(HtmlTextWriterAttribute.Value, month.ToString());
 75                 writer.RenderBeginTag(HtmlTextWriterTag.Option);
 76                 writer.Write(month.ToString());
 77                 writer.RenderEndTag();
 78             }
 79             writer.RenderEndTag();
 80
 81             /////////////////////////////////////
 82
 83             writer.Write("&nbsp;");
 84

 85             /////////////////////////////////////
 86             writer.AddAttribute(HtmlTextWriterAttribute.Name, YearListName);
 87             writer.AddAttribute(HtmlTextWriterAttribute.Id, YearListId);
 88             writer.RenderBeginTag(HtmlTextWriterTag.Select);
 89
 90             for (int year = 2008; year < 2015; year++)
 91             {
 92                 writer.AddAttribute(HtmlTextWriterAttribute.Value, year.ToString());
 93                 writer.RenderBeginTag(HtmlTextWriterTag.Option);
 94                 writer.Write(year.ToString());
 95                 writer.RenderEndTag();
 96             }
 97             writer.RenderEndTag();
 98
 99             writer.RenderEndTag();
100             writer.RenderEndTag();
101 //*****************************************************************************
102
103             writer.RenderBeginTag(HtmlTextWriterTag.Tr);
104             writer.AddAttribute(HtmlTextWriterAttribute.Colspan, "2");
105             writer.AddAttribute(HtmlTextWriterAttribute.Align, "center");
106             writer.RenderBeginTag(HtmlTextWriterTag.Td);
107             writer.AddAttribute(HtmlTextWriterAttribute.Name, SubmitButtonName);
108             writer.AddAttribute(HtmlTextWriterAttribute.Value, SubmitButtonText);
109             writer.AddAttribute(HtmlTextWriterAttribute.Id, SubmitButtonId);
110             writer.AddAttribute(HtmlTextWriterAttribute.Type, "submit");
111             writer.RenderBeginTag(HtmlTextWriterTag.Input);
112             writer.RenderEndTag();
113
114             writer.RenderEndTag();
115             writer.RenderEndTag();
116
117 //******************************************************************************
118
119
120         }

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved