Selected Value of dropdown Box in Custom control

Hi Experts,

I created a custom control which has Drop down controls as one control.

I'm able to set DataSource,DataValueField,DataTextField from the page.

But How can I get the Selectedvalue of the DropDown list from that Custom Control.

The Dropdown Controls' AutoPostBack is set to false

Any Idea on this ..Please


Thanks
Vizai
0
vizai
5/3/2007 11:18:54 AM
asp.net.custom-server-controls 3498 articles. 0 followers. Follow

3 Replies
456 Views

Similar Articles

[PageSpeed] 18

Do you expose the DDL from the control as a property? How do you set the DataTextField etc now? Post the code.
Thanks,

Teemu Keiski
Finland, EU
0
joteke
5/3/2007 6:18:37 PM

In Custom control I declared properties as b elow

 

public string DataValueField

{

get

{

object o = ViewState["DataValueField"];

if (o != null)

{

return (string)o;

}

return string.Empty;

}

set

{

ViewState[

"DataValueField"] = value;

}

}

 

public Object DataSource

{

get

{

object o = ViewState["dataSource"];

return o;

}

set

{

ViewState[

"dataSource"] = value;

}

}

public string SelectedValue

{

get

{

object o = ViewState["SelectedValue"];

if(o!=null)

return o.ToString();

return string.Empty;

}

set { ViewState["SelectedValue"] = drpCtrl.SelectedValue; }

}

 

but here I'm unable to get the Selected value of the DropDownBox (drpCtrl)

 

 


Thanks
Vizai
0
vizai
5/4/2007 3:44:49 AM

Hi,

if you instantiate the child control(s) in CreateChildControls, e.g you have in this case the DDL a child control, there's no sense in duplicating the property implementation.

 For example: SelectedValue already is handled by the drpCtrl, so instead of saving it into a ViewState member plus trying to grab from drpCtrl, you could just delegate the SelectedValue property to just access the SelectedValue of the drpCtrl

public string SelectedValue 
{


get{

	EnsureChildControls();
	return drpCtrl.SelectedValue;
}


set { 

	EnsureChildControls();
	drpCtrl.SelectedValue = value;
	
  } 
}
 EnsureChildControls call is there to ensure that child control created in CreateChildControls exists, e.g that CreateChildControls is guaranteed to be called before you access the child control(s)
Thanks,

Teemu Keiski
Finland, EU
0
joteke
5/7/2007 7:01:05 PM
Reply:

Similar Artilces:

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....

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...

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 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...

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...

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...

Creating Custom Controls With Custom Controls Inside Of Them
Hello, I am trying to create a custom control for creating tabs. The idea is that our designer can just use the control tags to generate the tabs.  The problem that I am running into is that I want to be able to have a custom control that allows any number of child custom controls. So there would be a TabContainer Control, and within that there would be any number of tabs.  The idea is similar to how an asp:DropDown list can have any number of ListItems within them.  Here is my code, any help is appreciated. 1 <!-- TAB CONTAINER -->2 <%@ Control Language=&...

Custom Control within a Control Control
I am developing a custom controls that will render headers for different web sites. Within these controls, I want to place another custom control that will change the language. I created the language control and had it implement IPostBackDataHandler. This control works fine if I drag it on a new web form, but if I tell a header custom control to render it problems occur. The Language Selector custom control does not have a Page member anymore and the event handlers do not work. Does anyone have any experience with doing something similiar? Anyone have any suggestions? Thanks, ...

Custom controls called from inside other custom controls???
I'm fairly new to writing controls in ASP.NET so, forgive the I am trying to create a base page class which will call 3 custom controls. This base page class will span across multiple projects hence the reason I am not creating user controls. These 3 custom controls are: 1. TopNav-uses render method to display an HTML table with graphics for top navigation. 2. ImagePairs-uses prerender method to add javascript code to manage what graphic is displayed in TopNav onMouseOver and onMouseOut 3. MgrHeader-uses render method to display an HTML table with s...

Custom Server Control with Child Controls
I have a custom server control <xx.Parent... /> which parses custom child controls <xx.Child... />. In Visual Studio 2008, IntelliSense shows me both when I start typing my control namespace. How can I prevent the child control from showing up in IntelliSense  unless I'm adding it within the parent tags?Thanks. --Rudy...

Control Dropdown w/in a custom control
Hi all, I'm making a pop-up help control an am having problems with a DIV over Dropdowns. I'm finding out that this is a relatively major problem in web development, since the HTML Dropdown is a Windows control built into the HTML Spec. Anyways, I want to make a dropdown in the control @ design time that has the webcontrols on the page. Does anyone know the directive that does this. I'm trying to simulate the RequiredFieldValidator.ControlToValidate property. At design time, the propert of this control provides a dropdown for all controls you have listed on the page you are desig...

Custom Events in Custom Server Control
 Hi There I've created a custom server control. I have extended it by adding my own event which fires in one of the aggregated control's event handlers. My probelms is that I would like to be able to specify the event handler for the event from the aspx file as a tag attribute.Does anyone know how to link the attribute of a customer server control tag in the aspx file to a custom event in the class source for the control?   I've done this several times with Custom Controls.  All I do is declare the event in the CustomControl's class public...

Custom Server Control With Child Control
All, I am currently putting together a very simple control. The new control outputs a table with two rows. The top row contains a heading and the bottom row will contain any other content. The control as it stands works perfectly well and I can place text into the content row no problem. Now, to the problem. Once I'd completed the control I figured it would be neat to enable the developer to add controls directly into the bottom row (content row) of the outputted table. As you probably know the WebControl class has a Controls collection which the developer can use to add any other...

Custom event for Custom server control
  Hi All, I have a custom server control (Multi selection drop downlist). This control contains AspxEditButton control(which is like textbox with button), check box list control and panel.I have to display all selected values in AspxEditButton at control is leaving that panel. How can i create LostFocus event for panel . Please anyone help meRegards, Anu All I can think of, is that there is a javascript "onblur" you could look into, maybe you could use some AJAX techniques to make that JavaScript event fire a server side ev...

Web resources about - Selected Value of dropdown Box in Custom control - asp.net.custom-server-controls

Portal:Law/Nominate/Selected article - Wikipedia, the free encyclopedia
Add the article in to a subpage of this portal, such as Portal:Law/Selected article/# , replacing the "#" with the number above the current highest. ...

F8: Facebook’s FbStart Initiative Will Give Selected Developers A $30K Kick-Start
... successful applications is likely a whole lot easier with $30,000 in free tools and services to start off with, and that’s exactly what selected ...

LEGO Shop - The LEGO Technic team has selected the winner... - Facebook
The LEGO Technic team has selected the winner of the Co-Creation Challenge! LEGO will be producing a limited run of 20,000 of this stunning set.... ...

baby365- Grand Doctor Ma Selected Students for iPad on the iTunes App Store
Get baby365- Grand Doctor Ma Selected Students on the App Store. See screenshots and ratings, and read customer reviews.

Selected Cheney Vice Presidential Photographs
... for photos found within these albums are Paul Morse, Karen Ballard, Kimberlee Hewitt, Shealah Craighead, and Chris Greenberg. These selected ...

[iOS Advice] How To Clarify Your Email Replies By Quoting Selected Text - YouTube
Follow me on Twitter: http://www.twitter.com/macmixing Like my Facebook page: http://www.facebook.com/macmixing RATE, COMMENT, SUBSCRIBE! :-) ...

Sait Faik Abasıyanık’s Selected Stories are tales that beguile all for their brevity
The influential Turkish writer's collection of short stories is often bizzare but never boring.

Animal of the Day: Lucius Has Been Selected as the U.K.’s ‘Happiest Cat’
He’s got one blue eye, one green eye and a heart of gold. British mobile phone company O2 recently held some “cat auditions” to find “the UK’s ...

Michael Sam becomes first openly gay player selected in an NFL Draft
Defensive end Michael Sam of the University of Missouri became the first openly gay player to be selected in a National Football League Draft ...

Refugee spinner selected for PM's XI
Fawad Ahmed has gone from asylum seeker to rubbing shoulders with Julia Gillard at The Lodge.

Resources last updated: 11/27/2015 5:49:26 PM