473,388 Members | 1,198 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

CheckBox List (Web Custom Control)

Hi,

I'm creating a custom checkbox list control which will take 2 arraylists as
input. (One will contain Names and other will contain 0s and 1s. 0 - uncheck
1- check).
I'm able to create the checkbox list. The problem is I'm unable to raise an
event when I select any of the checkboxes. Following is the code:

Could you guys please help me on this issue.

CUSTOM CONTROL CODE:

using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.Collections;

namespace CheckBoxControl
{
/// <summary>
/// Summary description for WebCustomControl1.
/// </summary>
public class WebCheckBoxControl : WebControl, IPostBackDataHandler
{
ArrayList GBNameList = new ArrayList();
ArrayList GBCodeFlagList = new ArrayList();
public event EventHandler Changed;

public String Text
{
get
{
return (String) ViewState["Text"];
}

set
{
ViewState["Text"] = value;
}
}

public virtual bool LoadPostData(string postDataKey,
System.Collections.Specialized.NameValueCollection postCollection)
{
String presentValue = Text;
String postedValue = postCollection[postDataKey];

if (presentValue == null ||
!presentValue.Equals(postedValue))
{
Text = postedValue;
return true;
}
return false;
}
public virtual void RaisePostDataChangedEvent()
{
OnChanged(EventArgs.Empty);
}
protected virtual void OnChanged(EventArgs e)
{
if (Changed != null)
{
Changed(this, e);
}
}
public void PerformHandShake(ArrayList NameList, ArrayList
FlagList)
{
if (NameList.Count == CodeFlagList.Count)
{
this.GBNameList = NameList;
this.GBCodeFlagList = CodeFlagList;
}
else // Show error
{

}
}

protected override void Render(HtmlTextWriter output)
{
try
{
int CheckBoxValue = 1;
string OutPut = "";
string st1 = "<Table>";

if (this.GBNameList.Count > 0)
{

for(int name = 0; name<this.GBNameList.Count;
name++)
{
string Name = this.GBNameList[name].ToString();
string CodeFlag =
this.GBCodeFlagList[name].ToString();
if (CodeFlag == "0") // Checked = False
{
OutPut = OutPut + this.GetOneString(Name,
CheckBoxValue, "0");
}
if (CodeFlag == "1") // Checked = True
{
OutPut = OutPut + this.GetOneString(Name,
CheckBoxValue, "1");
}

CheckBoxValue = CheckBoxValue + 1 ;
}

string st2 = "</Table>";
string CheckBoxeswithTable = st1 + OutPut + st2;
output.Write(CheckBoxeswithTable);
output.AddAttribute(HtmlTextWriterAttribute.Name,
this.UniqueID);
}
else
{
output.Write("CheckBox List Control");
}
}

catch(Exception ex)
{
output.Write("Errror building CheckBox List:<br>");
output.Write(ex.InnerException);
}
}
public string GetOneString(string Name, int CheckBoxValue, string
CodeFlag)
{
string ToGo = "";
try
{
// Construct CheckBox in the First Column
string st1 = "<TR>";
string st2 = "<TD>";
string st3 = "<input type=\"checkbox\" name=\"";
string st4 = Name;
string st5 = "\" value=\"";
string st6 = CheckBoxValue.ToString();
string st7 = "\"";
string st8 = "CHECKED";
string test = "";
string st9 =
">";
string st10 = "</TD>";

// Construct Name of CheckBox in the Adjacent Cell
string st11 = "<TD>";
string st13 = "<font size=\"2\" face=\"Arial\">" ;
string st14 = Name;
string st15 = "</font>";
string st16 = "</TD>";
string st17= "</TR>";

if (CodeFlag == "0")// Checked = False
{
ToGo = st1 + st2 + st3 + st4 + st5 + st6 + st7 +
test + st9 + st10 + st11 + st13 + st14 + st15 + st16 + st17 ;
}
if (CodeFlag == "1") // Checked = True
{
ToGo = st1 + st2 + st3 + st4 + st5 + st6 + st7 +
st8 + test + st9 + st10 + st11 + st13 + st14 + st15 + st16 + st17 ;
}
}
catch(Exception ex) // Show Error
{

}

return ToGo;
}
} // Class
} // NameSpace


USAGE ON THE PAGE:

HTML Section:

<%@ Register TagPrefix="cc1" Namespace="BranchCheckBoxControl"
Assembly="BranchCheckBoxControl" %>
<cc1:webbranchcheckboxcontrol id="WebBranchCheckBoxControl1" Changed =
"Changed" runat="server"></cc1:webbranchcheckboxcontrol>

Code-Behind Section:
public void Changed(object sender, System.EventArgs e)
{
TextBox1.BackColor = System.Drawing.Color.Green;
TextBox1.Text = "You clicked the button";
}

Thanks
Steven
Nov 17 '05 #1
0 2203

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Steven | last post by:
Hi, I'm creating a custom checkbox list control which will take 2 arraylists as input. (One will contain Names and other will contain 0s and 1s. 0 - uncheck 1- check). I'm able to create the...
0
by: Jay Douglas | last post by:
I'm trying to add a property to a Web Custom Control that behaves just like the ControlToValidate string property on the built in .net valuators. I basically want the list to show the various...
1
by: Frédéric Mayot | last post by:
Hi, Does anyone know why my web custom controls don't work in a class library and do work in a web custom control library ? Thank. Fred
1
by: JAPHET | last post by:
I have a web custom control consist of three text box i.e Employee number,First name, Last Name. I Created a web form with a Repeate control, I want to attach a Custom control to a repeater so as...
2
by: Brian Henry | last post by:
I want to create a web custom control (not a user web control) that I can add a XML translation control into, how would I do this? I am using the web custom control as a template that I can add to...
4
by: Steven | last post by:
Hello, I'm creating a list of buttons in web custom control. When I'm creating them I'm giving the name of each button as this.UniqueId. But this is aslways giving me the "WebCustomControl1" as...
0
by: Eachus | last post by:
Hello, I’m trying to create a web custom control. I’ve worked in asp.net extensively, but this is the first time I’ve attempted a web custom control. As a test, I created a control exactly...
1
by: Amelyan | last post by:
I need to create web custom control that can contain any type of control as a child (similar to asp:Panel control). However, when I try to include children in my web control on aspx page, it says...
4
by: rony_16 | last post by:
Hi, i wrote a web custom control, that adds a search option to list box. on of the properties are the position of the textbox that serves are search, the position is Enum (Up, Down). the code...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.