Setting control values from one user control to another

I have two user controls on a page.  Control 1 is view. Control2 is search.  User selects value on Control2 and I want to update Control1(View).  I cannot find syntax to change values on Control1 from Control2.  The following is function on Control1 that is called from Control2 after pageInit and load on Control1.  I have tried many many ways to findControl but all fail.

'Function on Control1 called from Control2 after Control1 PageInit/load:

        Public Function loadFormValues(ByVal intValue As Int32)

            Dim tb As New TextBox
            tb = parent.findControl("Control1").FindControl("tbsecure_lastname")' fails at finding textbox on Control1
            tb.Text = intValue 

        End Function

'Note: In this app I have no control of the page name or form name.


1/17/2006 3:43:21 PM 93655 articles. 6 followers. Follow

6 Replies

Similar Articles

[PageSpeed] 16

Sounds like you need to set the SELECT parameter of the datasource of your view to the control .text value of the textbox. Then have your button_click event do Datasource.Databind()
"nothing" really matters!
1/17/2006 5:15:51 PM

I'm not entirely clear on the hierarchy of your controls and how they are used, but does your Control1 contain simple set of controls or something more complex involving DetailsView or FormView?  My testing with simple user controls seems to indicate that your code should work.  If you have more complex hierarchy, then you may be missing a reference to one of the container when using FindControl().  Also, is your Control2 calling a function defined in Control1 (above code) and exactly where is this being called from (which event)?


1/17/2006 5:50:19 PM

I am calling from ItemCommand of linkbutton.

The hierarchy is defined by dotnetnuke more than I.

        Private Sub dgSearchResults_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dgSearchResults.ItemCommand
            Dim lButFname As LinkButton
            Dim objView As New viewSecMan

            lButFname = e.Item.FindControl("lbutFullName")
            'Catch ex As Exception

            'End Try

        End Sub

1/17/2006 7:48:50 PM
I'm not familiar with dotnetnuke (you may want to post your question on that thread), but it's possible that your control is embedded within another container which may need to be accessed before using the FindControl() function.  It all depends on your hierarchy involved.  FindControl() is one of the most confusing feature in this respect.  You may also want to do a search on this forum for "FindControl" since many topics were discussed under various conditions.  One of them may apply to your situation. Good luck.
1/17/2006 8:01:42 PM
I also want to note that exposing control values as properties in the senerio at the head of this post will yeild an "Object Not Found" error since the control has loaded.
1/18/2006 12:41:17 PM

You'd have to do that through the parent of the User Controls.

In User Control #1:
      Create a public property to the child control:
            public string ControlValue
                        return this.TextBox1.Text; 
                        this.TextBox1.Text = value; 

In User Control #2:
      Create a public property to the child control:
            public string ControlValue
                        return this.TextBox1.Text; 
                        this.TextBox1.Text = value; 

In the parent (aspx):
      Create global references to the User Controls
            protected YourUserControlA YourUserControlA1;
            protected YourUserControlB YourUserControlB1;

Then to set the property:
      YourUserControlB1.ControlValue = YourUserControlA1.ControlValue;



1/18/2006 5:17:25 PM

Similar Artilces:

want to call one function in one user control from another user control
hi i have two user controls info.ascx and personal.ascx i have a function like in info.ascx i have a function like showdetails() {   } now i want to access this function from personal.ascx can i do this ? thanks in advance. shwetaThanksshwetaIn a day when don't come across any problem -you can be sure that you are traveling in wrong path  you should better create a class where you will define the "functions" that you need in both files. declare "static" the function and call it like nameofclass.nameoffunction In a web project you can...

Pass value from one User Control to another User Control
I have tried to pass value from one user control to another user control. Because of Page Auto Postback, Contrls are load before page is loaded. So I get the value in 2nd UC after one more post back operation. I have visited many suggessions but I cant solve this. Is anyone can help me to solve this. Thank U Muhmmad Fakhrul HossainEmail: mfhossain@gmail.comPhone: +88 01715 111512Web: You'd have to do that through the parent probably in it's Page_Load event handler.   userControl1.publicProperty = userControl2.publicProperty;  ...

I have a web user control being used by another web user control, but the one being used will not display the labels in the resx file.
I am using DotNetNuke version 3.13 (might be 3.013) on a Window's XP machine, SP2. I have what I find to be an extremely odd situation. I have a project called TDS.Controls. This project is a web control library. Each control has its own resx file, which is located in the App_LocalResources directory. Each control inherits from Framework.UserControlBase, just like DotNetNuke's User control in DNN\Controls\User.ascx.vb. As a matter of fact, this control is doing the exact same thing I am trying to do. It is a web user control with its own resx file being used by another web user control (See ...

Updating a Label control in one user control from another user control
Hi all, I have a main page in my music store site that has 5 user controls on it with 1 always showing main content and the others being things like a shopping cart, "best sellers", genre list etc (a la amazon). From the main content control I want to be able to set some label controls in my shopping basket control but I just can't seem to work out the syntax for how to do this: Here's the code I'm using - I'm trying to go to the 4th user control on the page (my shopping basket) then find the appropraite label, cast it locally as a Label then update the value: Label _so...

How to pass control values from one ascx user-control to another???
Our site is set up using a primary default aspx page that is used as the "base page" for everything. On this page, we dynmaically place various user controls at run-time. This gives us a functionality similar to using frames where the outer-frame actually just sits there while various webfiles are loaded inside of it. Works great except for one thing... trying to figure out the best way to pass control names/values accross user controls. When the same usercontrol is posting back to itself this is a non issue. So far most of our functionality has worked well using the local...

Web user control inside update panel replace with another web user control
 Hi there. I have a page with a menu. an and then the content. My thing is. That i have the update panel, and inside that i have a regual panel in which i add the Web User Controls i need. Which all works fine. My problem is. That i i have a submit funcion on almoast all the Web User controls. What i would like is that i inside that update panel, can dispose the original Web user Control and then add a response Web User Control. In normal language. Is there a way that i can load one web user control into antoher and then disposose the original? Thanks in advance hello. well, what ...

Values set from one user control to another
I have two user controls on a page.  Control 1 is view. Control2 is search.  User selects value on Control2 and I want to update Control1(View).  I cannot find syntax to change values on Control1 from Control2.  The following is function on Control1 that is called from Control2 after pageInit and load on Control1.  I have tried many many ways to findControl but all fail. 'Function on Control1 called from Control2 after Control1 PageInit/load:         Public Function loadFormVa...

access controls on web user control x from web user control Y
I have 2 web users controls in a page and I would like to get or set the selected values of a few dropdown boxes on web user control X from web user control Y and I also would like to know how to access functions that are on a web user control X from a web user control Y, is this possible? How can I do it? User can access and set the values of the User Control from .aspx page through properties,using javascript and in code-behind of aspx page.The details of it are shown below Using PropertiesIf the Sample.ascx control has two textboxes and submit button.You can access the valu...

Gettin values from one user control in other user control
Hello,I have a web page in which I have to user controls UC1 and UC2.In UC1 there are few text boxes (eg: txtContactNumber etc...)In UC2 I have a button. On the click of the button I want to get the value entered  in the txtContactNumber textbox which is in UC1 user control.How to do this. Please let me know.Any code for the example if given is appreciated.Thank You.     In the codebehind for UC1 put the following:public string ContactNumber { get { return txtContactNumber.Text; } set { txtContactNumber.Text = value; } }  And in UC2:private string ...

Update one user control from another user control
I have two user controls (.ascx files) on one .aspx page. They are in some kind of master-detail relationship. When I select a row in the GridView in first control, second control is populated with editable data. After changing data and clicking update data IS saved but GridView in first control is not updated.How can I cause that data in first control refreshes, but to keep selected row selected?__Please mark post as answer if it helps, if not come back and ask again! Hi,You need to re-bind the GridView with the updated data source so that it reflects the latest changes. Regarding the cur...

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? Information Technolo...

Web User Control to Web User Control...
Hi, I have 2 User controls on a page and want Control1 to call a method of Control2. Is this Possible? Example: Con1 = Datalist showing products, each with a Quantity Box and a Button. Con2 = Repeater showing Cart Preview (name, Price) in page.aspx. When I click on the button on the DataList in Con1 it adds the item into the Session based Cart. However it does not update the Cart Preview. I need to call BindPreview() in Con2 in order to update the Cart Preview... Does that make sense? argh! any help much appreciated! PeteWeb Design Nottingham, UK Well I can call BindPreview() from m...

How to call a function from one User Control from another User Control
Hi, I have one User Control in a page, the User Control has a button, when the user clicks on the button, I need to call a function within another User Control (on the same page).  I have made a function public, but I don't know see the function from the other User Control. Can you help me please, Thank you! Aldo have u added a delegate event for the button clicked like in the example below. ////////WebUserControl1 public partial class WebUserControl1 : System.Web.UI.UserControl {public delegate void ButtonClciked(object sender, EventArgs e); public event B...

How to access one user control from another user control on same page
hi,I have two usercontrol on same page. 1.ascx and 2.ascx on abc.aspx . Now I need to access dropdown on 1.ascx frm 2.ascx . Plz help me how can i do this?I have tried Page.findcontrol but as a user control inherits usercontrol class and not page class . its not giving reference to proeprty Page.Findcontrol. I can do page.findcontrol on aspx page but I need to do it on ascx only.plz helpregards,max   Hi Max, you have to expose your DropDownList as a public property which lays inside usercontrol 1. Example: 1 class MyUserControl1 : UserControl 2 { 3 4 p...

Web resources about - Setting control values from one user control to another -

Help:Contents/Account settings and maintenance - Wikipedia, the free encyclopedia
Wikipedia® is a registered trademark of the Wikimedia Foundation, Inc. , a non-profit organization.

Mode setting - Wikipedia, the free encyclopedia
Mode setting can be done in kernel space ( Kernel Mode Setting or KMS) or in user space ( User-space Mode Setting , UMS). Doing mode setting ...

5 Facebook Privacy Settings You Must Review Now
Facebook now has five different settings for controlling whether and how you get tagged on the site.

Analysis: Facebook’s New Privacy Settings a Major (and Risky) Step Toward Openness
The upcoming changes to Facebook’s privacy settings will allow users to control who they share information with every time they post a piece ...

'Delusions' setting Australia up for a big budget shock: Ross Garnaut
The case for company tax cuts for large business has not been subject to "rigorous analysis" according to leading economist Ross Garnaut. ...

Setting Up A Successful Exam-Taking Strategy: 3 Tips For Test Preparation
Are you scared? Good! Because if you are, then you are taking final exams seriously.

In pilot program, Uber is setting drivers up with rental cars
Uber is partnering with Enterprise to rent cars to potential Uber drivers for $210 a week in a pilot program that’s launching this week in Denver, ...

NFL Fantasy Football Week 13: Last-Minute Advice for Setting Your Roster - Bleacher Report
It wasn't so long ago when fantasy drafts were fresh, and our rosters were stocked and stable. When that Eddie Lacy and Dez Bryant combo felt ...

Why did Obama choose the Oval Office setting for his speech and then stand behind a lectern?
Shouldn't he have sat at his desk? I see Callum Borchers at The Washington Post has asked the same question: Whatever the impetus, let's get ...

Setting caution aside, Red Sox went all in for an ace
There was little effort at secrecy — actually, make that none — as a rather unusual dinner party took their places at the table at the Southern ...

Resources last updated: 12/11/2015 4:24:30 AM