Passing Controls to Controls

I have built a very simple DropDown control similar to what Microsoft uses on their website, and the one listed in the control gallery. This control exposes 2 properties, Title and Text. The code looks something like this:

<script>
Public PassedTitle as String
Public PassedText as String
....
....
MyText.Text=PassedText
</script>
....
....
<asp:Literal id="MyText" />
I also have another control that scans the DB at my workplace and pulls up the last 10 articles that have been posted to the knowledgebase and lists their titles and hyperlinks to them.
What I'd like to do is pass the "Last 10 posts" control into the "Dropdown" control so that the last 10 posts show up in the dropdown.
Various things will be passed to the dropdowns, such as login controls, news, etc.
Any ideas on the best way to do this? I am looking into using Templated controls, but I am still fairly "template stupid" and figuring it out.
Thanks
Todd Davis (todd.davis@ceridian.com)
-Todd Davis
http://www.SeaburyDesign.com
0
toddhd
7/23/2002 6:08:17 PM
asp.net.hosting-open-forum 4216 articles. 0 followers. Follow

4 Replies
1043 Views

Similar Articles

[PageSpeed] 30
Get it on Google Play
Get it on Apple App Store

What exactly do you mean by passing a login control to a dropdown? Do you mean that, if I click on the dropdown, the code should take me to the login control?
Shanku Niyogi





This posting is provided "AS IS" with no warranties, and confers no rights.
0
shankun
7/24/2002 11:00:51 PM
Hi, shankun

I have similiar problem.
In one page, I have 2 user controls:
in first user control i built a drop down list.
In the second user control I need to get the parameter from the first control(SelectedItem.value), so that I can build my SQL statement.
Is that possible?
Thanks
adam
0
awang3
7/29/2002 7:45:02 PM
Sure, you can do this from your user control, by calling Page.FindControl("userctrl1ID"), where userctrl1ID is the ID of the first user control. 

However, it's generally better to have the user controls expose properties and events, and to have your page code catch the right event from the first control and set a property on the second. This encapsulates all the functionality of each control within the control, rather than making controls dependent on each other.
For example, in your user control 1, do this:

<script runat="server" language="c#">
public event SelectedItemChanged;
public String SelectedItem {
get {
return combo.Items[combo.SelectedIndex].Value;
}
}
void Combo_SelectedIndexChanged(Object sender, EventArgs e) {
// Raise the same event on ourselves.
if (this.SelectedItemChanged != null) {
this.SelectedItemChanged(this, e);
}
}
</script>
<asp:DropDownList runat="server" id="combo" OnSelectedIndexChanged="Combo_SelectedIndexChanged" />

In your second user control, do this:

<script runat="server" language="c#">
public void DoQuery(string query) { get {
// Build SQL statement
}
</script>

Then, in your page, you can do this:

<%@ Register TagPrefix="acme" Name="ctl1" Src="ctl1.ascx" %>
<%@ Register TagPrefix="acme" Name="ctl" Src="ctl2.ascx" %>
<script runat="server" language="c#">
private string _query;
void Ctl1_SelectedItemChanged(Object sender, EventArgs e) {
Ctl2.DoQuery(Ctl1.SelectedItem);
}
</script>
<acme:Ctl1 runat="server" id="Ctl1" OnSelectedItemChanged="Ctl1_SelectedItemChanged" />
<acme:Ctl2 runat="server" id="Ctl2" />

Shanku Niyogi





This posting is provided "AS IS" with no warranties, and confers no rights.
0
shankun
7/29/2002 10:46:22 PM
could you please do a vb.net example with a submit button on control 1 activating after updating database  activating another user control rebinding event for a child datagrid

if you could please help ASAP I have a big deadline and this has me completely stumped
thanks heaps
0
Wal474
2/7/2004 5:50:30 AM
Reply:

Similar Artilces:

How do I control one control from another control?
I have a page page1.aspx which is within a master page. On page I have a table with two cells. Within each cell I have placed two controls (ascx) that I have developed. Now I'd like to be able to get these two controls to interact. One needs to update the other. One has some search criteria that the other one needs to update its gridview. One needs to make the other visible/not visible at certain times. Out of the box neither control can see each other at all. Is there a good article or someplace I can find some information on how to do this?  AllAboutFocus.com. Information Technolo...

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

how to raise server control event(control defined inside user control) from host page?
I have built a user control(using c#,net 2.0,VS2005,MS-SQL server 2005),which contains set of 3 button,save,cancel and next and wud be reused/displayed in multiple pages.As the name says,they are suppose to update on save,reset the fields   on cancel and navigate to another page on next.How do i raise the onClick event for all of these button individually,from the individual host page?I do not have/do not prefer any logic,event handler etc.. defined in the user control for these buttons,since every host page have different set of parameters for save,cancel etc.Thanks...

Trouble controlling .net controlls with CSS
 I am trying to control the :hover css property on <asp: Button> controls. Basically the css is working correctly to set the initial look of the button, but nothing is happening when I hover over the button. Here is my code:CSS:.sidebarButton{    width: 168px;     height: 45px;     background-color: #666666;     text-align: left;    font-weight: bold;    font-family: Century Gothic;    font-size: 13pt;    color: White;    border-style: none;  ...

AJAX Control Toolkit + hosting a control
My host has recently added support for AJAX Extensions 1.0 (they do not mention the Control Toolkit though) and I would like to add a slider control from the toolkit to my site. So I have some questions... (1) Will controls taken from the control toolkit work online or does the hoster have to have the AjaxControlToolkit.dll on their server ?  (2) If the web host does not have AjaxControlToolkit.dll, can I just include it in my site ? If I can, how do I reference it (I am currently just taking the control from my toolbox but surely this will set a reference to wherever I have...

passing control to custom control as attribute
Hi, I am trying to pass for example a textbox to a custom web user control. So I can access a specific textbox from the custom control. Kinda like the "controlToValidate" attribute. I thought I could find the control in the custom control through the page.findcontrol function, but that doesn't work. Control.ascx.vb Public Class testControl1 Inherits System.Web.UI.UserControl Private WithEvents tb As System.Web.UI.WebControls.TextBox Public Property controlToChange() As String Get Return tb.ID End Get ...

Passing Html controls value to Controller
Alright, I have dynamically created Html controls using Html Helper. Now, to pass data to my controller I use Request.Form in code-behind and create Session variables with the results, so I can read them from my controller. Is there a "Better" way to pass data to controller, knowing that I have dynamically created controls, from which I want to retreive value Thanks for help You can pass data from controller to view using ViewData (I think that it is not your problem). If you want to process data from HTML Form then you do it using Request.Form directly. But in MVC th...

Trying to load a control into a control from another control
Exactly as the subject states, I'm trying to load a control into another control from a control loaded into a page, I keep getting this error from the code I have below. I've also tried the findcontrol but it keeps coming up null. (67): 'System.Web.UI.UserControl' denotes a 'class' where a 'variable' was expected UserControl ut = ((webcontrols.BrowseItems)UserControl).LoadControl("BrowseItems"); ((webcontrols.BrowseItems)UserControl).pnl_browse_main.Controls.Add(ut); This is how we Load User controls into a content place holder. try { UserCont...

How do you control the placement of controls in a user define control
I have a user define control.  I put the control on the (C# Visual Studio 2008) page where I want them. When I run the program, the controls are all over the page.  How do I place them where they do not move form where I put them? You'll need to study the HTML output and see what it's producing, then start to look at how to do an HTML layout. hi, there are absolute and Relative position in html. I guess you must use relative position. For example, at design-time, you place a TextBox below an Image, at run-time, no matter what size is the image, the TextBox is alway bel...

Raise event from IE hosted windows user control and catch it in the Web Form that’s hosting the control
Hi. I have a web app that uses a IE hosted windows user control. I would like that, somehow, lounch an external event from that hosted control that I could catch in my web form’s code behind. If possible, please send a small sample project (bozesan_mihai82@yahoo.com). I would appreciate any suggestions! Thanks in advance! Hello, I am not sure of the *IE hosted windows user control*, but check this post to see if this helps you or not: Define a Custom Event inside UserControls HTH RegardsBilal Hadiar, MCP, MCTS, MCPD, MCTMicrosoft MVP - Telerik MVP...

What is the real difference between Server Controls and .NET controls?
This was a class discussion question and I'd like to know, what exactly are the differences? Is there a clear answer? .NET framework controls are server controls. The only difference that I can think of is that the .NET controls are part of the FCL (Framework Class Library). HTH,RyanRyan OlshanASPInsider | Microsoft MVP, ASP.NEThttp://ryanolshan.comHow to ask a question...

how to pass the values html controls to server control
I need to pass the  javascript output value to server control. <script>var myval = javascriptfunctionoutput </script> i have to pass myval to server control.<asp:hidden runat=server id="Message">document.getelementByID("Message").text = myval once i pass this value i have to get in .aspx.cs file like this  Message.Text = "passed value"but its not working.. Any suggestion ...plz      shiva If the html control is part of a server control, once the page is rendered, its clientID is probably not "Message" but something like "MyControl_Mess...

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

Making the .NET calendar control as a floating control
Hi, I need to implement the .NET calendar control as a floating control. Is it possible to do that? If so, can you let me know how to do that?With Regards,Saravana Kumar M R  You could use the calendar extender control in the AJAX control toolkit. You can download the toolkit here, and there is a sample here.My Blog...

Web resources about - Passing Controls to Controls - asp.net.hosting-open-forum

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

WA bushfires: Firefighters work through the night to control several blazes
Firefighters in Western Australia are working through the night to control and contain several blazes.

MAZEL TOV, HILLARY: Clinton Wins Gun Control Award From Major Anti-Bill of Rights Group
... restrictions on the freedoms protected by the Constitution is not a sign of character, but a clear indication of blind adherence to a gun control ...

Democrats New Plan For Gun Control – A Secret Government Terrorist Watch List
They call it the "Denying Firearms and Explosives to Dangerous Terrorists Act of 2015"

The Legend of Zelda: Twilight Princess Wii U will likely support Wiimote and Nunchuk controls
Well this is interesting. Fans have been speculating as to the control schemes that will be supported in The Legend of Zelda: Twilight Princess ...

USB Volume Control
... computer speakers, they often have a volume knob you can mount somewhere on your desk so you aren’t dependent on the onboard volume control. ...

ICYMI: Even the AP couldn’t validate any of Hillary’s gun control nonsense
... – not 200 as she claimed . Asked to explain the discrepancy, Clinton’s campaign pointed to 2013 statistics from the Centers for Disease Control ...

5 Questions: Punjab’s rightful control over Chandigarh, says Prem Singh Chandumajra
Shiromani Akali Dal (Badal) MP Prem Singh Chandumajra on why he raised the issue of Punjab’s claim over Chandigarh in LS.

Over-The-Counter Birth Control Empowers Women And Pharmacists In Oregon And California
Over-the-counter birth control is coming to Oregon and California. There’s an enactment of new laws on the horizon that will allow pharmacists ...

In this Dark Fairy Tale, a Sheltered Young Girl Seizes Control of Her Future
“In a family headed by a tyrannical father, the younger daughter will regain her freedom on her birthday.” It’s a simple synopsis, but Blood ...

Resources last updated: 11/26/2015 9:01:40 AM