[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

URGENT: Composite control button event not firing

Posted on 2005-05-13
5
Medium Priority
?
748 Views
Last Modified: 2006-11-18
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;
          }
     }
0
Comment
Question by:Robinsonx6
  • 3
  • 2
5 Comments
 
LVL 6

Accepted Solution

by:
dharmesh_amity earned 1500 total points
ID: 13996873
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
 
LVL 2

Author Comment

by:Robinsonx6
ID: 13997205
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
 
LVL 6

Expert Comment

by:dharmesh_amity
ID: 13997588
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
 
LVL 6

Expert Comment

by:dharmesh_amity
ID: 13997644
Sorry But my last comment is not true
0
 
LVL 2

Author Comment

by:Robinsonx6
ID: 13997804
no problems and yes your correct it isnt true :-)
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses
Course of the Month19 days, 9 hours left to enroll

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question