URGENT: Composite control button event not firing

Hi i have created a custom composite control using c# and it displays perfectlly on the web page, when the button is clicked the assosiated event is not firing Please can someone help:-

WEB Code Login.aspx

<%@ Page language="c#" Codebehind="Login.aspx.cs" AutoEventWireup="false" Inherits="House.Login" %>
<%@ Register TagPrefix="cc1" Namespace="CHR" Assembly="Register" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
     <HEAD>
          <title>Login</title>
          <meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
          <meta name="CODE_LANGUAGE" Content="C#">
          <meta name="vs_defaultClientScript" content="JavaScript">
          <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
     </HEAD>
     <body MS_POSITIONING="GridLayout">
          <form id="Login" method="post" runat="server">
               <cc1:Register id="Register1" runat="server"></cc1:Register>
          </form>
     </body>
</HTML>

Control Code:

using System;
using System.Data.SqlClient;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace CHR
{
     /// <summary>
     /// Summary description for SearchControl.
     /// </summary>
     public class Register: Control, INamingContainer
     {
          protected Panel               pnl = new Panel();

          protected Label               lbl_title = new Label();
          protected DropDownList     ddl_title = new DropDownList();
          protected Label               lbl_name = new Label();
          protected TextBox          txt_name = new TextBox();
          protected Label               lbl_county = new Label();
          protected DropDownList     ddl_county = new DropDownList();
          protected Label               lbl_telephone = new Label();
          protected TextBox          txt_telephone = new TextBox();
          protected Label               lbl_email = new Label();
          protected TextBox          txt_email = new TextBox();
          protected Label               lbl_password = new Label();
          protected TextBox          txt_password = new TextBox();
          protected Label               lbl_cpassword = new Label();
          protected TextBox          txt_cpassword = new TextBox();
          protected Button          btn_register = new Button();

          protected override void CreateChildControls()
          {
               Controls.Add(pnl);
               pnl.Controls.Add(new LiteralControl("<table width=150 border=0>"));
               pnl.Controls.Add(new LiteralControl("<tr>"));
               pnl.Controls.Add(new LiteralControl("<td colspan=3 height=40 valign=bottom align=right>&nbsp;"));
               pnl.Controls.Add(new LiteralControl("</td>"));
               pnl.Controls.Add(new LiteralControl("</tr>"));
               pnl.Controls.Add(new LiteralControl("<tr>"));
               pnl.Controls.Add(new LiteralControl("<td width=165>"));
               pnl.Controls.Add(lbl_title);
               pnl.Controls.Add(new LiteralControl("</td>"));
               pnl.Controls.Add(new LiteralControl("<td >"));
               pnl.Controls.Add(ddl_title);
               pnl.Controls.Add(new LiteralControl("</td>"));
               pnl.Controls.Add(new LiteralControl("</tr>"));
               pnl.Controls.Add(new LiteralControl("<tr>"));
               pnl.Controls.Add(new LiteralControl("<td>"));
               pnl.Controls.Add(lbl_name);
               pnl.Controls.Add(new LiteralControl("</td>"));
               pnl.Controls.Add(new LiteralControl("<td >"));
               pnl.Controls.Add(txt_name);
               pnl.Controls.Add(new LiteralControl("</td>"));
               pnl.Controls.Add(new LiteralControl("</tr>"));
               pnl.Controls.Add(new LiteralControl("<tr>"));
               pnl.Controls.Add(new LiteralControl("<td>"));
               
               pnl.Controls.Add(lbl_county);
               pnl.Controls.Add(new LiteralControl("</td>"));
               pnl.Controls.Add(new LiteralControl("<td>"));
               pnl.Controls.Add(ddl_county);
               pnl.Controls.Add(new LiteralControl("</td>"));
               pnl.Controls.Add(new LiteralControl("</tr>"));
               pnl.Controls.Add(new LiteralControl("<tr>"));
               pnl.Controls.Add(new LiteralControl("<td>"));              
                   
               pnl.Controls.Add(lbl_telephone);
               pnl.Controls.Add(new LiteralControl("</td>"));
               pnl.Controls.Add(new LiteralControl("<td>"));
               pnl.Controls.Add(txt_telephone);
               pnl.Controls.Add(new LiteralControl("</td>"));
               pnl.Controls.Add(new LiteralControl("</tr>"));
               pnl.Controls.Add(new LiteralControl("<tr>"));
               pnl.Controls.Add(new LiteralControl("<td>"));

               pnl.Controls.Add(lbl_email);
               pnl.Controls.Add(new LiteralControl("</td>"));
               pnl.Controls.Add(new LiteralControl("<td>"));
               pnl.Controls.Add(txt_email);
               pnl.Controls.Add(new LiteralControl("</td>"));
               pnl.Controls.Add(new LiteralControl("</tr>"));
               pnl.Controls.Add(new LiteralControl("<tr>"));
               pnl.Controls.Add(new LiteralControl("<td>"));

               pnl.Controls.Add(lbl_password);
               pnl.Controls.Add(new LiteralControl("</td>"));
               pnl.Controls.Add(new LiteralControl("<td>"));
               pnl.Controls.Add(txt_password);
               pnl.Controls.Add(new LiteralControl("</td>"));
               pnl.Controls.Add(new LiteralControl("</tr>"));

               pnl.Controls.Add(new LiteralControl("<tr>"));
               pnl.Controls.Add(new LiteralControl("<td>"));

               pnl.Controls.Add(lbl_cpassword);
               pnl.Controls.Add(new LiteralControl("</td>"));
               pnl.Controls.Add(new LiteralControl("<td>"));
               pnl.Controls.Add(txt_cpassword);
               pnl.Controls.Add(new LiteralControl("</td>"));
               pnl.Controls.Add(new LiteralControl("</tr>"));

               pnl.Controls.Add(new LiteralControl("<tr>"));
               pnl.Controls.Add(new LiteralControl("<td colspan=2 valign=Bottom height=40 align=right>"));
               pnl.Controls.Add(btn_register);
               pnl.Controls.Add(new LiteralControl("</td></tr></table>"));
          }
          protected override void OnPreRender(EventArgs e)
          {
               pnl.HorizontalAlign=HorizontalAlign.Center;
               pnl.BackImageUrl="images/registerbox_bck.gif";
               pnl.Width=222;
               pnl.Height=311;
               pnl.EnableViewState=false;

               lbl_title = configureLabel(lbl_title,"Title");
               lbl_name = configureLabel(lbl_name,"Full Name");
            lbl_county = configureLabel(lbl_county,"County");
               lbl_telephone = configureLabel(lbl_telephone,"Telephone");
               lbl_email = configureLabel(lbl_email,"E-Mail");
               lbl_password = configureLabel(lbl_password,"Password");
               lbl_cpassword = configureLabel(lbl_cpassword,"Confirm Password");

               txt_name = configureTextBox(txt_name);
               txt_telephone = configureTextBox(txt_telephone);
               txt_email = configureTextBox(txt_email);
               txt_password = configureTextBox(txt_password);
               txt_cpassword = configureTextBox(txt_cpassword);

               ddl_title = configureList(ddl_title,"Title");
               ddl_county = configureList(ddl_county,"County");

               btn_register.Command += new CommandEventHandler(btn_Command);
               btn_register.ID="btn_register";
               btn_register.CommandArgument="register";
               btn_register.Text=" Register ";
               
          }
          protected void BtnInit(object sender, EventArgs e)
          {
               btn_register.Command += new CommandEventHandler(btn_Command);
          }
          protected void btn_Command(object sender, CommandEventArgs e)
          {
               HttpContext.Current.Response.Write("Register Clicked");
          }

          private Label configureLabel(Label lbl,string strName)
          {
               lbl.Text= strName;
               lbl.Style["color"]="#FF0000";
               lbl.Style["font-family"]="Arial";
               lbl.Style["font-size"]="13";
               lbl.Font.Bold=true;    
               return lbl;
          }
          private TextBox configureTextBox(TextBox txt,string strName)
          {
               txt.Text= strName;
               txt.Width=55;
               txt.Style["color"]="#696969";
               txt.Style["font-family"]="Arial";
               txt.Style["font-size"]="13";
               txt.Font.Bold=false;    
               return txt;
          }
          private TextBox configureTextBox(TextBox txt)
          {
               txt.Style["color"]="#696969";
               txt.Width=115;
               txt.Style["font-family"]="Arial";
               txt.Style["font-size"]="13";
               txt.Font.Bold=false;    
               return txt;
          }
          private DropDownList configureList(DropDownList ddl,string strname)
          {
               ddl.Width=115;

               ddl.Style["color"]="#696969";
               ddl.Style["font-size"]="11";
               ddl.Style["font-family"]="Arial";

               return ddl;
          }
     }
LVL 2
Robinsonx6Asked:
Who is Participating?
 
dharmesh_amityConnect With a Mentor Commented:
I think BtnInit is not called. You will have to

override protected void OnInit(EventArgs e)
{
      InitializeComponent();
      base.OnInit(e);
}

private void InitializeComponent()
{
         btn_register.Command += new CommandEventHandler(btn_Command);
}
0
 
Robinsonx6Author Commented:
thanks but sorry it didnt work but the initialise was being called and the event was built but at runtime it didnt fire again, i was assuming that this had something to do with the viewstate but i could be wrong
0
 
dharmesh_amityCommented:
I see that you are using Command event instead of Click Event. Do you need to pass arguments to that event. I see that you are not using that.

Anyway if you want to use Command event, then you will need to set the CommandName while creating that control.

btn_register.CommandName = "SomeCommand";

Hope this fixes the problem.
0
 
dharmesh_amityCommented:
Sorry But my last comment is not true
0
 
Robinsonx6Author Commented:
no problems and yes your correct it isnt true :-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.