简体   繁体   中英

How to pass data from page to user control and vise versa in asp.net C#?

I have a main page called Mainpage1 and inside that page one usercontrol called UC1 and inside that usercontrol we have another usercontrol called UC2.

Here I want to pass the data from UC2 to Mainpage and vise versa. How can I achieve this?

Thanks in advance Siva

You'll need to use javascript or AJAX. So make a javascript function that hooks into UC2's change event. Inside that function you can change the css/html/etc on the main page. If what you're trying to do requires you to go back to the controller for some sort of processing (ie checking the value against a database) then you'll need to use ajax to call the url for that action.

Without seeing any code that's the best I can tell you.

(From question 542410 )

In the code-behind on your user-control expose a property eg

public TextBox UserControlTextBox
{
    return this.TextBoxInstance;
}

Then from you page just call

UserControlInstance.UserControlTextBox.Text;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM