Can anyone please help with custom server control?
I have all layout and inputs, select, buttons and images using javascript client side but I'd like to use with server side instead.
Instead of using: <input type="submit" id="cmdSubmit" name="submit" value="submit" onclick="javascript:SubmitButton" />
I would like to use this: <asp:Button id="cmdSubmit" Text="Submit" onclick="btn_SubmitClick" runat="server" />
this is my c# class.
namespace ncToolBar
{
//-public class ncToolBar : UserControl
[ToolboxData("<{0}:ncToolBar runat=server></{0}:ncToolBar>")]
public class ncToolBar : WebControl
{
#region clsProperties
private bool bShowMonthYearPeriod = false;
public bool ShowMonthYearPeriod
{
get { return bShowMonthYearPeriod; }
set { bShowMonthYearPeriod = value; }
}
private bool bShowDateRange = false;
public bool ShowDateRange
{
get { return bShowDateRange; }
set { bShowDateRange = value; }
}
private int iPeriodMonth = 0;
public int MonthPeriod
{
get { return this.iPeriodMonth; }
set {this.iPeriodMonth=value; }
}
private int iPeriodYear = 0;
public int MonthYear
{
get { return this.iPeriodYear; }
set { this.iPeriodYear=value; }
}
private string sStartDate = "";
public string StartDate
{
get { return this.sStartDate; }
set { this.sStartDate = value; }
}
private string sStopDate = "";
public string StopDate
{
get { return this.sStopDate; }
set { this.sStopDate = value; }
}
private string sRefreshIConPath = "";
public string RefreshICon
{
get { return this.sRefreshIConPath; }
set { this.sRefreshIConPath = value; }
}
private string sPDFIConPath = "";
public string PDFIcon
{
get { return this.sPDFIConPath; }
set { this.sPDFIConPath=value; }
}
private string sExcelIConPath = "";
public string ExcelICon
{
get { return this.sExcelIConPath; }
set { this.sExcelIConPath = value; }
}
private string sPrintIConPath = "";
public string PrintICon
{
get { return this.sPrintIConPath; }
set { this.sPrintIConPath = value; }
}
#endregion
protected override void RenderContents(HtmlTextWriter output)
{
output.AddAttribute(HtmlTextWriterAttribute.Id, this.ID);
output.AddAttribute(HtmlTextWriterAttribute.Width, this.Width.ToString());
output.AddAttribute(HtmlTextWriterAttribute.Height, this.Height.ToString());
if (ShowMonthYearPeriod == true)
{
output.AddAttribute("controls", "controls");
}
if (ShowDateRange == true)
{
output.AddAttribute("controls", "controls");
}
if (MonthPeriod > 0)
{
output.AddAttribute("monthperiod", "monthperiod");
}
if (MonthYear > 0)
{
output.AddAttribute("monthyear", "monthyear");
}
if (RefreshICon != "")
{
output.AddAttribute("refreshicon", "refreshicon");
}
if (ExcelICon != "")
{
output.AddAttribute("excelicon", "excelicon");
}
if (PDFIcon != "")
{
output.AddAttribute("pdficon", "pdficon");
}
if (PrintICon != "")
{
output.AddAttribute("printicon", "printicon");
}
}
protected override void Render(HtmlTextWriter writer)
{
string sDblQuote = "\"";
//string sDivStyle = "border: 1px solid black; width: 739px; font-size: 9pt; padding: 0px; margin: 0px; background-color: #d8d6d6; position: relative; vertical-align: middle; top: 0px; left: 0px;";
writer.WriteFullBeginTag("div style=" + sDblQuote + "border: 1px solid black; width: 739px; font-size: 9pt; padding: 0px; margin: 0px; background-color: #d8d6d6; position: relative; vertical-align: middle; top: 0px; left: 0px;" + sDblQuote +" align=" + sDblQuote + "center" + sDblQuote +"\n");
writer.Write("<table border='0' width='80%' cellpadding='0' cellspacing='0' id='table2'>\n");
writer.Write("<td style='font-family: Verdana, Arial, Microsoft Sans Serif; font-size: 10pt;' align='left'>");
if (ShowMonthYearPeriod == true)
{
writer.Write(" ");
writer.Write("Period: <select ID=" + sDblQuote + "ddlMonth" + sDblQuote + " name=" + sDblQuote + "ddlMonth" + sDblQuote + "style=" + sDblQuote + "font-size: 8pt; vertical-align: middle;" + sDblQuote + " runat=" + sDblQuote + "server" + sDblQuote + ">\n");
writer.Write("<option value=" + sDblQuote + "0" + sDblQuote + ">---SELECT---</option>\n");
writer.Write("<option value=" + sDblQuote + "1" + sDblQuote + ">January</option>\n");
writer.Write("<option value=" + sDblQuote + "2" + sDblQuote + ">February</option>\n");
writer.Write("<option value=" + sDblQuote + "3" + sDblQuote + ">March</option>\n");
writer.Write("<option value=" + sDblQuote + "4" + sDblQuote + ">April</option>\n");
writer.Write("<option value=" + sDblQuote + "5" + sDblQuote + ">May</option>\n");
writer.Write("<option value=" + sDblQuote + "6" + sDblQuote + ">June</option>\n");
writer.Write("<option value=" + sDblQuote + "7" + sDblQuote + ">July</option>\n");
writer.Write("<option value=" + sDblQuote + "8" + sDblQuote + ">August</option>\n");
writer.Write("<option value=" + sDblQuote + "9" + sDblQuote + ">September</option>\n");
writer.Write("<option value=" + sDblQuote + "10" + sDblQuote + ">October</option>\n");
writer.Write("<option value=" + sDblQuote + "11" + sDblQuote + ">November</option>\n");
writer.Write("<option value=" + sDblQuote + "12" + sDblQuote + ">December</option>\n");
writer.Write("</select>\n");
writer.Write("<select ID=" + sDblQuote + "ddlYear" + sDblQuote + " name=" + sDblQuote + "ddlYear" + sDblQuote + "style=" + sDblQuote + "font-size: 8pt; vertical-align: middle;" + sDblQuote + " runat=" + sDblQuote + "server" + sDblQuote + ">\n");
writer.Write("<option>" + DateTime.Now.AddYears(-3).Year.ToString() + "</option>\n");
writer.Write("<option>" + DateTime.Now.AddYears(-2).Year.ToString() + "</option>\n");
writer.Write("<option>" + DateTime.Now.AddYears(-1).Year.ToString() + "</option>\n");
writer.Write("<option>" + DateTime.Now.Year.ToString() + "</option>\n");
writer.Write("</select>\n");
}
if (ShowDateRange == true)
{
writer.Write(" ");
writer.Write("Range: Start-Date: <input type=" + sDblQuote + "text" + sDblQuote + "ID=" + sDblQuote + "txtStart" + sDblQuote + "name=" + sDblQuote + "txtStart" + sDblQuote + " style=" + sDblQuote + "font-size: 8pt; width: 80px; vertical-align: middle;" + sDblQuote + " runat=" + sDblQuote + "server" + sDblQuote + " />");
writer.Write("Stop-Date: <input type=" + sDblQuote + "text" + sDblQuote + "ID=" + sDblQuote + "txtStop" + sDblQuote + "name=" + sDblQuote + "txtStop" + sDblQuote + " style=" + sDblQuote + "font-size: 8pt; width: 80px; vertical-align: middle;" + sDblQuote + " runat=" + sDblQuote + "server" + sDblQuote + " />");
}
writer.Write("<input type=" + sDblQuote + "submit" + sDblQuote + "ID=" + sDblQuote + "cmdRun" + sDblQuote + "name=" + sDblQuote + "cmdRun" + sDblQuote + " value=" + sDblQuote + "Run" + sDblQuote + " style=" + sDblQuote + "font-size: 7pt; vertical-align: middle;" + sDblQuote + " OnClick=" + sDblQuote + "btn_ExecuteReport" + sDblQuote + " runat=" + sDblQuote + "server" + sDblQuote + " />");
writer.Write("</td>\n");
writer.Write("<td align=" + sDblQuote + "right" + sDblQuote + ">");
writer.Write(" ");
writer.Write("<input type=" + sDblQuote + "image" + sDblQuote + "id=" + sDblQuote + "imgButRefresh" + sDblQuote + " src=" + sDblQuote + "images/RefressCtrl.gif" + sDblQuote + " onclick=" + sDblQuote + "javascript:window.location.reload( true );" + sDblQuote + " alt=" + sDblQuote + "Refresh" + sDblQuote + " title=" + sDblQuote + "Refresh" + sDblQuote + " style=" + sDblQuote + "vertical-align: middle;" + sDblQuote + " />");
writer.Write(" | <input type=" + sDblQuote + "image" + sDblQuote + "id=" + sDblQuote + "imgButExport" + sDblQuote + " src=" + sDblQuote + "images/excel_icon.gif" + sDblQuote + " onclick=" + sDblQuote + "btn_ExcelExportClick" + sDblQuote + " alt=" + sDblQuote + "Excel" + sDblQuote + " title=" + sDblQuote + "Excel" + sDblQuote + "style=" + sDblQuote + "vertical-align: middle;" + sDblQuote + " />");
writer.Write(" | <input type=" + sDblQuote + "image" + sDblQuote + "id=" + sDblQuote + "imgButPrint" + sDblQuote + " src=" + sDblQuote + "images/PrintCtrl.gif" + sDblQuote + " onclick=" + sDblQuote + "javascript:tablePrint();" + sDblQuote + " alt=" + sDblQuote + "Print" + sDblQuote + " title=" + sDblQuote + "Print" + sDblQuote + "style=" + sDblQuote + "vertical-align: middle;" + sDblQuote + " />");
writer.Write(" | <input type=" + sDblQuote + "image" + sDblQuote + "id=" + sDblQuote + "imgButClose" + sDblQuote + " src=" + sDblQuote + "images/close_icon.jpg" + sDblQuote + " onclick=" + sDblQuote + "btn_CloseClick" + sDblQuote + " alt=" + sDblQuote + "Close" + sDblQuote + " title=" + sDblQuote + "Close" + sDblQuote + "style=" + sDblQuote + "vertical-align: middle;" + sDblQuote + " />");
if (ShowDateRange == true)
{
writer.Write(" </td>\n");
}
else
{
writer.Write(" </td>\n");
}
writer.Write("</tr>\n");
writer.Write("</table>\n");
writer.WriteEndTag("div");
this.RenderContents(writer);
}
}
}
TIA