Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8192267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T04:08:17+00:00 2026-06-07T04:08:17+00:00

I have a simple question in asp.net. I want to know if it is

  • 0

I have a simple question in asp.net.
I want to know if it is possible to get data from controls in my user control directly . I want to do it without using Session variable,Viewstate …

EDIT: I now use the method of declaring public variables in the UC.

Here is a part of Page_load from my parent page:

 this.plan_action = (UCPlan)Page.LoadControl("~/Association/UCPlan.ascx");
 PlaceHolder1.Controls.Add(this.plan_action);

 if (this.plan_action.Validate == true)
        {
            CheckBox1.Checked = true;
            //String référence = Session["liste_action"].ToString();

            for (int i = 0; i < this.plan_action.List1.Count; i++)
            {
                Label8.Text += this.plan_action.List1[i].Référence + "/";
                //Label8.Text += "/";
            }


        }

but my variable validate stay to false.

Here is the code where I change the value of the validate variable with it declaration:

    private bool validate;

    public bool Validate
    {
        get { return validate; }
        set { validate = value; }
    }


 protected void Button2_Click(object sender, EventArgs e)
      {


          //myCommand.Connection = myConnection;
          //Session["liste_action"] = this.List;
          this.Validate = true;
          //Response.Redirect("../Risques_folder/AjouterRisque.aspx");


      }

Thank you for your help,

Quentin

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T04:08:18+00:00Added an answer on June 7, 2026 at 4:08 am

    UPDATE due to new information

    You need to learn about the sequence of events in ASP.NET.

    The Load of the page happens a long time before the Click handler of Button2 in your UserControl… so the Validate property is always going to be set to false.

    You have two obvious options (as I see it)…

    Keep the creation of the UserControl in your Page_Load (or preferably, move it to your Page_Init, as this is normally the most appropriate place for it). Then place your check for the Validate property in a Page_PreRender.

    Or, create an Event in your UserControl, Raise that event on the click of Button2, and handle the event in the Page.


    ANOTHER UPDATE

    For the 2nd of the two options above, in your UserControl class have the following…

    public delegate void ButtonClickedDelegate(object sender, EventArgs e);
    public event ButtonClickedDelegate ButtonClicked;
    

    In the Button2_Click method of the UserControl (after setting the this.Validate = true;) call…

    ButtonClickedDelegate(sender, e);
    

    In the Page_Init of the Page, put something like…

    ctrl1.ButtonClicked += new UCPlan.ButtonClickedDelegate(ctrl1_ButtonClicked);
    

    And then have a new method called something like

    void ctrl1_ButtonClicked(object sender, EventArgs e)
    {
        if (ctrl1.Validate)
        {
            ...
        }
    }
    

    Remember, as you control the delegate you can pass whatever information you want, including an entire class. So instead of calling the Validate property, create a new instance of the class you want, and pass that as a delegate parameter.

    You can find more information on delegates and events on MSDN.



    ORIGINAL ANSWER

    Unless I’ve missed something, this is a very simple ASP.NET concept…

    You can create properties and/or methods.

    For example, as a property…

    public string MyProperty
    {
      get { return "My Property Value"; }
    }
    

    Or as a method

    public string MyMethod()
    {
       return "My Method Value";
    }
    

    If you’re talking about passing the values between the UserControl and the ASP.NET Page that contains it, then in your Page, you can simply call the property or method. If your control was called (for example) myCtrl, then you can something like…

    string prop = myCtrl.MyProperty;
    string meth = myCtrl.MyMethod();
    

    (On the back of the great comment from AHMED EL-HAROUNY)
    If you’re talking about passing the values to the client side page, then you can use the same properties / methods directly in the HTML markup. However, in this case, the properties / method can be declared as protected rather than public

    For instance, to display the value…

    <%=MyProperty%>
    

    Or

    <%=MyMethod()%>
    

    Or if you’re going to use the value in javascript, something like…

    var myProp = "<%=MyProperty%>";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

A simple question. I have an ASP.NET web application which contains several assemblies and
simple question... Given I have an ASP.NET site, which uses a [custom] RoleProvider, Is
I have what should be a fairly simple ASP.NET question, and one I thought
Pretty simple question. I have a few ASP RequiredFieldValdators checking some text boxes. Out
I have simple question. User supplies URL to my PHP script where I fetch
I have a simple question. I'm trying to get a list of the indicators
I only want facts as far as possible. There are some things that ASP.Net
I have various simple ASP.NET MVC views for CRUD operations which work fine on
I have a very simple asp.net mvc web app which uses castle active record,
My question is as follows: I have a base controller (ASP.Net MVC controller) called

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.