473,770 Members | 4,419 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.W ebControls;
using System.Componen tModel;
using System.Collecti ons;

namespace CheckBoxControl
{
/// <summary>
/// Summary description for WebCustomContro l1.
/// </summary>
public class WebCheckBoxCont rol : WebControl, IPostBackDataHa ndler
{
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(st ring postDataKey,
System.Collecti ons.Specialized .NameValueColle ction postCollection)
{
String presentValue = Text;
String postedValue = postCollection[postDataKey];

if (presentValue == null ||
!presentValue.E quals(postedVal ue))
{
Text = postedValue;
return true;
}
return false;
}
public virtual void RaisePostDataCh angedEvent()
{
OnChanged(Event Args.Empty);
}
protected virtual void OnChanged(Event Args e)
{
if (Changed != null)
{
Changed(this, e);
}
}
public void PerformHandShak e(ArrayList NameList, ArrayList
FlagList)
{
if (NameList.Count == CodeFlagList.Co unt)
{
this.GBNameList = NameList;
this.GBCodeFlag List = CodeFlagList;
}
else // Show error
{

}
}

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

if (this.GBNameLis t.Count > 0)
{

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

CheckBoxValue = CheckBoxValue + 1 ;
}

string st2 = "</Table>";
string CheckBoxeswithT able = st1 + OutPut + st2;
output.Write(Ch eckBoxeswithTab le);
output.AddAttri bute(HtmlTextWr iterAttribute.N ame,
this.UniqueID);
}
else
{
output.Write("C heckBox List Control");
}
}

catch(Exception ex)
{
output.Write("E rrror building CheckBox List:<br>");
output.Write(ex .InnerException );
}
}
public string GetOneString(st ring 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.T oString();
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="Bran chCheckBoxContr ol"
Assembly="Branc hCheckBoxContro l" %>
<cc1:webbranchc heckboxcontrol id="WebBranchCh eckBoxControl1" Changed =
"Changed" runat="server"> </cc1:webbranchch eckboxcontrol>

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

Thanks
Steven
Nov 17 '05 #1
0 2233

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

Similar topics

0
473
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 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.
0
1048
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 different textboxes on the current web form. I've searched, and searched, and can not find an answer. A link, or any help is appreciated. Thanks in advance.
1
961
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
1239
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 I can add a multiple rows at a time to my employee table. PLz help me how can i achieve this. Japhet.
2
1480
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 the page, but it depends on other Web Form controls inside it but I do not know how to add the other web form controls such as a XML web form control into this programatticly created control. thanks
4
1108
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 the UniqueId. So for each button the UniqueId is "WebCustomControl". Is there anyway I can declare the UniqueID to be the 'Integer x', which will increment in a loop starting from 1. So Button1 will get UniqueID as 1,... How can I do this?
0
1435
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 as described in one of the walkthroughs (except for a couple of grammatical changes that the vs.net IDE insisted on). The one thing I did different was to compile it via the IDE rather than the command line. But it doesn’t work. In design...
1
1102
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 'Content is not allowed between the opening and closing tags for element'. Does any one have an example of how to build this simple web custom control? Thanks,
4
1040
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 looks like that : namespace SearchList { public Enum SearchListLoacation
0
9602
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10237
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10071
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
6690
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5326
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5467
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3987
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3589
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2832
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.