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 0 2234 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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.
|
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.
|
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
|
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.
|
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
| |
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?
|
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...
|
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,
|
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
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
| |
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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();...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |