To pass values from one user control to another

Hi,

      I have a page where there is a user control. inside that user control(let's say Usercontrol1) i have another user control(lets say Usercontrol2). in the usercontrol2 i have a tree and a button. When the page gets loaded first the treeview in the usercontrol2 should not get populated only when i click on a button in the Usercontrol1, then only the treeview in the Usercontrol2 should get populated. also i want to pass the text of a selected treenode when i click on the usercontrol2's button to a textbox in the usercontrol1. can someone tell me how to do it with an example in C#. i am new to programming.

Thanks,

Jollyguy

1
jollyguy77
3/7/2008 6:14:16 AM
asp.net.web-forms 93655 articles. 6 followers. Follow

2 Replies
660 Views

Similar Articles

[PageSpeed] 8

From usercontrol1 pass values into usercontrol2 is easy . make public property like

public TextBox txtFromUserControl2

{ get {return txtbox;}

set {txtbox = value;}

}

and then from user control1, just call

UserControl2.txtFormUserControl2 and it will allow you set or get this object

From UserControl2 call userControl1 is little trick, you can use delegate or bubble event 

See url for details

http://www.odetocode.com/Articles/94.aspx  


Don't forget to click "Mark as Answer" on the post(s) that helped you.
1
TonyDong
3/7/2008 6:27:00 AM

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 ButtonClciked OnbuttonClicked;

protected void Page_Load(object sender, EventArgs e)

{

}

protected void Button1_Click(object sender, EventArgs e)

{

if (OnbuttonClicked != null)

{

OnbuttonClicked(sender, e);

 

}

}

}

 

 

///WebUserControl2

public partial class WebUserControl2 : System.Web.UI.UserControl

{

protected void Page_Load(object sender, EventArgs e)

{

}

public void FunctionToCall()

{

 

}

}

//////uractauall page in which both control resides

public partial class Third : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{

this.WebUserControl1_1.OnbuttonClicked+=new WebUserControl1.ButtonClciked(WebUserControl1_1_OnbuttonClicked);

}

public void WebUserControl1_1_OnbuttonClicked(object sender, EventArgs e)

{

this.WebUserControl2_1.FunctionToCall();

}

}

 

//try to follow the example

this example is successfully calling the funtion in the user control 2 u can also call any thing in ur user control

hope this helps

sam

mark this as answer if the post helps


Saima Ghumman
--Mark the post as Answer if the Post helps you--
0
Sam
3/7/2008 6:44:41 AM
Reply:

Similar Artilces:

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 mfhossain@gmail.com Muhmmad Fakhrul HossainEmail: mfhossain@gmail.comPhone: +88 01715 111512Web: http://www.mfhossain.info You'd have to do that through the parent probably in it's Page_Load event handler.   userControl1.publicProperty = userControl2.publicProperty;  ...

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

want to call one c#.net 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...

Passing Values from a Web Form to Another Web Form
Hello All! I am trying to pass values from one web form to another web form. I know that there are 3 ways of doing this: queryString, Server.Transfer and Session. I am using the Server.Transfer method. But I am not able to create, in my 2nd web form, an instance of my 1st web form. My 1st Web form is named CallTrack.aspx and my 2nd is named Export.aspx. What I mean is something like this: Public value as CallTrack. I can't create it in my 2nd web form because when the intellisense is displayed, there's no CallTrack in the options. Thanks!   How about using cross-...

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

pass value from one user control to another
i have a web page (Page.aspx) that contains a main user control (Main.ascx) which has two other controls within it (A.ascx, B.ascx). I have a text box and a button in A.ascx, when the user clicks the button i want the text in the textbox to be captured and then displayed on B.ascx. I have seen a few discussions on this using RaiseEvent but I'm not sure how to do it. Does anyone have any ideas? check this tutorial in codeproject thanks rasheeda, this post helped me out alot also. http://www.asp.net/Forums/ShowPost.aspx?tabindex=1&PostID=115712 ...

How do you pass a value from one user control to another?
There must be an example of this somewhere but if there is I can't find it. I have a web form containing 2 user controls. The first displays a list of people. The user selects the person they are interested in and details of that person are to be displayed in the second user control. What is the best way of passing the selected item from the first user control to the second. I can do it with session variables, but there must be a better way than that. thanks You can use properties for that.User Controlprivate string m_Person;public string Person{    get {...

Passing values from one web control to another.
I'm trying to pass a value from one user control to another. Basically, the first user control selects an id number and then the second user control takes that id number and updates a record in a database. I have the second control set up to accept values using public string idnumber; public string IDnumber { set { idnumber = value; } } The second user control has two buttons that do postbacks, depending on which is clicked, a value is updated in the database identified by this number. The problem I am having is that before I click th...

Pass Values from a user control to a web form
Hi All,  I am currently trying to add captcha to my webform. I have a question on how to pass a number/string from a .ascx to a .aspx page. The aspx is being used in the .ascx (user control) in an image tag. <asp:Image ID="imgCaptcha" runat="server" ImageUrl="Image.aspx"/> The aspx page is being rendered as a jpeg image. So Inorder for the captcha to be displayed with the image, I need to pass the code from the user control to the aspx page. I have an option to pass the number as a query string or use it in session. But is there any ot...

Pass values from one user control to a user control on a different aspx page
Hello, I have an aspx page titled Search.aspx. Within this page, I have a user control titled Search.ascx. I want a user to input search terms, then on the click of a button, I want to pass the values to another page (SearchResults.aspx)....which will then display the results in a user control. Can someone please give me some suggestions on how to do this? Thanks a lot! Hello, what you can do is: inside ur usercontrol, create a method that returns a dataset or datareader. that is, since u are searching using the usercontrol, then the result of ur search will be return...

How to use a web user control from one web app in another web app?
I have a production web app project (at work) that has custom web user controls in it.I have another web app project for experimenting and I want to use some web controls from the production web app. The big trick is that I need to load the controls dynamically.LoadControl() doesn't seem to work - it complains about loading controls from a different application. I also tried adding a project reference to the production web app and using "UC1 newUC = new UC1();" and then "this.Controls.Add(newUC);", but the controls (like TextBoxes) on the web user control don't seem to exist on the new UC1s....

Trying to pass values from one control to another control
I have 2 controls on my page. CaseList and Email Reviwer. CaseList contain a datagrid that when the button (5th column) is clicked 2 values should be passed to the email revier control. In the email Reviwer Control I have declared: I have: public void sendCaseIdCatId(int catid,int caseid) { ViewState["EmailReviewerCategoryId"] = catid; ViewState["EmailReviewerCaseid"] = caseid; } in my EmailReviwer control   I tried: //Display the email reviewer panel EmailCaseReviewer.Visible=true; string strcatid = e.Item.Cells[1].Text.ToString(); string strcaseid = e.Item.Cells[0].Text.T...

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

Pass data from Web User Control to Web Form
I have a Web Form that contains a Web User Control. The WUC displays dynamic content. I want to change the TITLE property of the Web Form, based on the contents of the WUC. For example, if the WUC displays information about Horses, I want to change the page title to "HORSES" by passing the string to the parent Web Form. I have tried playing with parameters and such, but I can't remember how I did this in the past. PLEASE HELP!~o0 Spin-Monkey Oo~ The best way to do this is by creating a public property on your web user control and accessing that from your web form. Check ...

Web resources about - To pass values from one user control to another - asp.net.web-forms

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

Out-of-control car hits Ballajura pedestrians and puts four teens in hospital
Four teenagers were injured in Ballajura on Saturday night when an out-of-control car careered into them.

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

EU could soon have border controls
EU ministers have agreed to press ahead with plans to suspend the Schengen passport-free travel zone, the FT reports.

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

Christie: Democratic Gun Control Proposals Are ‘Just Like Eating Cotton Candy, It Does Nothing Good’
Christie: Democratic Gun Control Proposals Are ‘Just Like Eating Cotton Candy, It Does Nothing Good’

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

Facebook Gives Users More Control Over Viral Content In News Feed
Facebook is updating its algorithm to give users more control over how high viral content appears in their News Feed.

Resources last updated: 12/6/2015 8:28:36 AM