Custom web control. Get Textbox.text value

Hi

 I have created a custom web control that extends the CheckBoxList control. It basically is a CheckBoxList control that has a TextBox added to the end of each CheckBox. It looks like the following after it has being bound to a database table column.


I need to be able to retrieve the values in the corresponding TextBox when a CheckBox is selected. I tried storing each TextBox in an ArrayList but it is always empty when I try and check it. I am pretty new to ASP and am obviously missing something. Has anybody here got any tips or ideas on how I could retrieve the data from the TextBoxes in this control. I have posted the current code  below.

public class EARCheckTextList : CheckBoxList, IRepeatInfoUser
{
	private TextBox box;
	
	public EARCheckTextList()
	{
		box = new TextBox();
	}
	
	protected override void RenderItem(System.Web.UI.WebControls.ListItemType itemType, int repeatIndex, RepeatInfo repeatInfo, HtmlTextWriter writer)
	{
		base.RenderItem(itemType, repeatIndex, repeatInfo, writer);
		box.ID = "TB" + repeatIndex.ToString(NumberFormatInfo.InvariantInfo);
		box.Enabled = this.Enabled;
		box.Attributes.Clear();
		box.Width = 50;
		box.RenderControl(writer);
	}
}
 
Thanks for any help given.
John 
0
ClearZ
5/14/2007 8:03:17 PM
asp.net.custom-server-controls 3498 articles. 0 followers. Follow

6 Replies
840 Views

Similar Articles

[PageSpeed] 43

I think the value of the textboxes are being lost during postback. Maybe you need to add this value to the viewstate of your control.

 German Afanador
 


German Afanador
0
Trebolin
5/14/2007 8:55:45 PM
Hi Trebolin. Yes the values are being lost because once a postback happens the values disappear from the textboxes. I have no idea how to do this as I'm very new to ASP.
0
ClearZ
5/14/2007 9:50:28 PM

Try exposing the TextBox of your custom control as a public property like so:

 

public TextBox box{
   get{return (TextBox)ViewState["box"];}
}

also on the constructor should do this:

	public EARCheckTextList()
	{
		ViewState["box"] = new TextBox();
	}

  eliminate the box private property.
and on the RenderItem method do this:
  
	protected override void RenderItem(System.Web.UI.WebControls.ListItemType itemType, int repeatIndex, RepeatInfo repeatInfo, HtmlTextWriter writer)
	{
                TextBox box = (TextBox)ViewState["box"];
		base.RenderItem(itemType, repeatIndex, repeatInfo, writer);
		box.ID = "TB" + repeatIndex.ToString(NumberFormatInfo.InvariantInfo);
		box.Enabled = this.Enabled;
		box.Attributes.Clear();
		box.Width = 50;
		box.RenderControl(writer);
	}
 
Hope this helps guiding you.
 
German Afanador 

German Afanador
0
Trebolin
5/14/2007 10:04:47 PM

Thanks again for the help but it still isnt working I tried the following also which just puts 1 textbox at the end of the list but I can never retrieve the value from it and it dosent retain its value after a postback

 

 

    public class EARCheckTextList : CheckBoxList, IRepeatInfoUser
    {
        public TextBox box
        {
            get { return (TextBox)ViewState["box"]; }
        }

        public EARCheckTextList()
        {
            ViewState["box"] = new TextBox();
        }

        protected override void Render(HtmlTextWriter w)
        {
            base.Render(w);
            TextBox box = (TextBox)ViewState["box"];
            box.ID = "T0";
            box.Enabled = this.Enabled;
            box.RenderControl(w);
        }
    }
  
0
ClearZ
5/14/2007 10:46:00 PM

You should try reading a control creation tutorial. You might find something you can use here: http://msdn2.microsoft.com/en-us/asp.net/aa336658.aspx

 

German Afanador 


German Afanador
0
Trebolin
5/14/2007 11:25:41 PM

Thanks a million for the help. Ive been rushed into this project using ASP without much knowlege of the subject. I am a JSP/PHP developer. I am impressed with ASP.NET overall and intend to spend time gaining a greater knowlege it.

 Thanks again for the help

John.

0
ClearZ
5/15/2007 10:08:07 AM
Reply:

Similar Artilces:

Custom Server Control Vs Web Parts, Any need for Custom Server Control
Hello I've just posted a similar question on why you need server controls when you can pre-compile usercontrols and redistribute them. http://forums.asp.net/p/1397433/3010100.aspx#3010100 I've seen lots of (usercontrol vs web part) but not much on web part vs custom server control. According to the MSDN site you can put web parts onto a normal asp.net page outside of a web part zone and they behave just like custom server controls. So, if you are creating a bunch of controls for redistribution to customer asp.net sites and/or SharePoint sites why don't you just create Web Par...

Web Custom Control within a Web Custom Control
I was wondering if this can be done and how. I've created a simple custom control that displays a header which is my first custom control. So I'm just a baby when it comes to this.. Within the header I currently have a property for breadcrumbs which is a string. What I would like to do is have the breadcrumb property  be a Link Button List. I did find a custom control of a Link Button List which is exactly what I wanted. My question is how can/do  I include this into my custom control? Can it done? How? Please help? I'm at a lose here.   Susan You should be able to do ...

Custom Web Control inside another Custom Web Control
Hi I created a custom web control (CusWebNew) that displays some textboxes by adding them to the ControlCollection of the webcontrol. I also created a custom webcontrol (CustWebButton) that inherts from Button control, and overrided the OnClick function. When I use CustWebButton on a regular web form, it seems to function correctly. However, when I added to be part of the ControlCollection of CustWebNew, it stops to work.   Any ideas why? Thanks Hey, What do you mean by stops to work?  Explain what you are trying to do with it and what it doesn't do.Brian"Trust in the...

Server Web User Control or Web Custom Control
Ok, I made a DataGrid I like, stuck it in a Web Control Lib, and then to my toolbar. Now I want to take my nice little control and add it to a greater control, maybe place some buttons around it etc. I could always inherit from it in a new custom control and dynamically add the buttons, but I thought about using a Web User Control. I thought I could easily create a Web User Control, drop on my grid and the buttons on a form, and expose some properties and events, but once I got into it, I got a feeling that this isn't what a Web User Control is for. When designing a control li...

Usercontrol vs Custom Server Controls, Any need for Custom Server Controls
Hello I'm new to ASP.Net so this is probably a stupid question but, is there any need to create customer server controls now that you can pre-compile usercontrols into a dll and thus easily share between applications? This blog post from David Ebb describes how to do it and the restrictions he note don't seem that bad (other than being able to embed resources such as images in the dll). http://blogs.msdn.com/davidebb/archive/2005/10/30/487160.aspx His article desribes the techniques for ASP.Net 2.0 and he suggests that there will be further improvements in .Net 3.5 in this ar...

Custom Server Control Made of Custom Controls?
I'm giving myself a crash course in custom server controls, and I have a quick general question. Can I have a custom server control that is composed of other server controls I created. I'm pretty sure the answer is yes, but I want to be positive. Yes http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpcondevelopingcompositecontrols.asp Shows how to combine existing controls into a new control using class composition. -ron Thanks! ASP.NET so rocks! Making page components extensible objects is such a great idea! I love it....

problems listenening to events on a custom server control from another custom server control
 Hi all,I am having problems listening to events on one of custom server controls(AddBookmark) from another custom server control(BookmarkList). The listener or the BookmarkList control has a property that can be set to the AddBookmark control (string at design but the reference is obtained at run-time). I am able to get a reference to the AddBookmark control and add a listener to it on the BookmarkList control on the OnPrender of BookmarkList. But the problem is that when the events on AddBookmark gets fired, the listener added from the BookmarkList is no longer present and the listene...

Custom User Controls v. Custom Web Controls
Hi! Is it better for me to begin coding my controls instead of just designing them? What would the benefits be? I meen, i seem to be able to get all i need from just putting stuff together on an ASCX file but i'm obviously missing a huge concept here... please explain! Hi, creating user controls is indeed easier than creating custom server controls because you can simply drag & drop other controls on the form, easily add events to it, ... Custom controls however are better when you want to reuse them in several other projects. I like to create custom controls for small, reusable com...

Add .Net Control to Web Custom Control
 I want to add .NET Control (like: TextBox, Button...) to Web Custom Control.How i can do it? Alphavn That's called a composite control -- "Mark As Answer" if my reply helped you -- Hello Guys What gunteman said, that is one approach and in most cases the right one.But its also possible to add child controls to a Control thats inherit from WebControl itself. Be sure to implement INamingContainer to that inherited Control too, thats the important point of that approach.--Microsoft MVP - Visual Developer ASP / ASP.NET- http://www.aspnetzone.de/blogs/peterbuch...

Web Custom Control
Hi. I created 4 drop downlist controls as web custom controls, which I would either like to use seperately, or working together like a hierarchy (dependant on each other). The problem is, I need to communicate with the calling control (the web page where I dragged these controls on). When the dropdownlists are used seperately, they should return all items on a table, but when they are used together, the child dropdownlist should only return items from the table based on the selection of the parent dropdownlist just above it. Can anyone please help? Thanks. You should post this in the Build...

Custom composite contorl contains custom contols: controls collection gets empty (Or control get reinitialized) on postback.
Hi, I'm  developing a ASP .Net custom server control library. Where all the basic(Text,check,etc) controls are working well. I have developed an composite control which is more like a Tabular control with the basic custom controls in every cell. The problem is, this composite control reinitializes on post back. I 've added the custom controls (in CreateChildControls method) as cell.controls.add(customcontrol)  row.controls.add(cell) ; this.controls.add(row) Please give me a solution as early as possible IMXO. ASP.NET constructs and reinitializes&n...

how to have both server controls and html controls rendered in a custom control?
I have a custom control in which there is an html text box.when you click on it , a div containing a table is appeared and according to what you select in that table a text is set to the text box. It works fine but the problem is: as the text box is an html element it doesn't have viewstate and when a post back occures in the page its value disappeares.I tried a hidden field to keep its value.again there is another problem : I put this custom control in a usercontrol and put the usercontrol in a multiview and by clicking on a button this view is selected and by clicking another bu...

Web custom control does not maintain values of child controls
Hello everybody A few days now, I am struggling with a custom web control I am creating, which consists of 3 drop down lists (country/city/hotel).Procedure is simple: On country change, I have to fill the cities with autopostback, and on city change I have to fill hotels again with auto postback. I tried many many methods and I am confused... The best I managed to make is keep the state of countries, and render it with the selected country, selected while filling cities with apporpriate data, however I cannot manage to do the same with the cities/hotels since sities does not keep selected va...

Custom Control within a Custom Control
I have two individual custom controls say custom cc1 and cc2. cc1 is communicating to cc2 using event delegate mechanism.I have tested the behaviour by dropping cc1 and cc2 onto a Web Page and it works fine. I want to create a third custom control say cc3 which should contain both cc1 and cc2. So that if i drag and drop cc3 onto a Web Page i can acheive exactly what i am doing above. The problem is that i am not sure how to call/register a custom control within a custom control ? Any clue ? Thanks!! Hi, Do you mean adding custom control to custom control? I think you can use the same wa...

Web resources about - Custom web control. Get Textbox.text value - asp.net.custom-server-controls

Control - Wikipedia, the free encyclopedia
Text is available under the Creative Commons Attribution-ShareAlike License ;additional terms may apply. By using this site, you agree to the ...

Amazon takes control of delivery with thousands of semi truck trailers
As Amazon looks for new ways to speed up delivery, the company on Friday announced the purchase of thousands of semi truck trailers. The Seattle-based ...

Is Hillary Clinton sorry she reacted to the San Bernardino massacre with a call for more gun control ...
... "Gun safety" has traditionally meant handling your guns safely, but now it's supposed to mean what has more commonly been called "gun control." ...

more pics from Ground Control Touring 15th anniversary: Woods, Kurt Vile, Parquet Courts, Beach Fossils ...
... Parquet Courts / Woods & Kurt Vile / Beach Fossils @ Webster Hall 12/2/2015 We already posted a review and set of pictures from Ground Control ...

Trump pushes alternative to gun control after attack
Billionaire hits back against New York Times editorial calling for stronger gun control in wake of San Bernardino massacre

Liberals Soft On Bomb Control? Are You Sure You Want To Go There, Marco?
... reports: Appearing on Fox & Friends , 2016 GOP presidential contender Marco Rubio hammered at Democrats for proposing additional gun control ...

Violent Crime In California Is Above National Average Despite Strict Gun Control
Violent Crime In California Is Above National Average Despite Strict Gun Control

Open thread for night owls: First U.S. birth control clinic lasted just 10 days before being raided
... Parenthood Only Lasted for 10 Days but Started a Revolution . An excerpt: During her time in Europe, Sanger had seen Norwegian birth control ...

The Federal Reserve Does Not Control The Federal Funds Rate
... rates at their next meeting it's worth just pointing out a little detail about how this all works. The Federal Reserve simply does not control ...

Gun buys, applications likely to surge as pols push gun control laws
Gun buys, applications likely to surge as pols push gun control laws

Resources last updated: 12/6/2015 12:28:37 AM