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 4111890
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T22:07:27+00:00 2026-05-20T22:07:27+00:00

I’ve a asp:TextBox and a submit button on my asp.net page. Once the button

  • 0

I’ve a asp:TextBox and a submit button on my asp.net page. Once the button was clicked, the TextBos’s value is posted back. I’m going to keep the the posted-back text value into session, so that other child controls can access to the value during their Page_Load. However, I always get NOTHING (“”) in the Page_Load method, and I can read the text out in the button click handler. I know that the “button click event” happens after the Page_Load. So, I’m asking how can I “pre-fetch” the TextBox.text during Page_Load?

public partial class form_staffinfo : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e){
        string s = staff_id.Text; //Reach this line first, but GET empty value. However, I want to keep it in the session during this moment.
    }

    protected void btn_submit_Click(object sender, EventArgs e) {
        string s = staff_id.Text; //Reach this line afterward, value got.
    }
}

— EDITED —

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="form_staffinfo.ascx.cs" Inherits="form_staffinfo" %>
<asp:Label ID="Label1" runat="server" Text="Staff ID: "></asp:Label>
<asp:TextBox ID="staff_id" runat="server" ></asp:TextBox>
<asp:Button ID="btn_submit" runat="server" Text="Query" OnClick="btn_submit_Click" />

Since I can’t get the TextBox’s text in the Page_Load, so, I didn’t include any code related to session for clear presentation.

Thank you!
William

  • 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-05-20T22:07:27+00:00Added an answer on May 20, 2026 at 10:07 pm

    None of the values of your server controls are available for consumption in the Page_Load. Those controls are assigned after the form is validated (which is after the form is loaded) and before the form’s control’s events fire (like button clicks, in your example). The values posted are in the Request.Form Collection. Look in the AllKeys property and you should see a key that ends in $staff_id if you use your example posted. There may be other characters in from of the key, depending upon if the control is nested in a master page or other control.

    If you absolutely must have that value at page load, grab it from the Request.Form collection instead of the user control, but I would question the wisdom of capturing the value that early in the page lifecycle. You could conceivably capture the textbox’s OnTextChanged Event if you needed to preserve the value in Session.

    EDIT – Additional Explanation
    if you were going to create a custom event for your user control, there are only a couple of steps to it.

    Create a delegate. This is will be the common object for inter-control messaging.

    public delegate void StaffIdChangedEvent(object sender, string staffId);
    

    Declare an event using that delegate in the user control that is going to broadcast.

    public event StaffIdChangedEvent StaffIdChanged;
    

    In your user control, when you are ready to broadcast (say from the Staff_id textbox’s OnTextChanged event), you just invoke the event [Its generally a best practice to check to see if the event is null]

    this.StaffIdChangedEvent(this, "staff-id-value-here");
    

    The final step is to wire the user control event up to an event handler (this prevents the null situation I mentioned above when trying to invoke the event). You could wire a handler into the hosting page.

    this.form_staffinfo.StaffIdChangedEvent += this.some_method_on_page;
    

    Just make sure the method on the page has the same method signature as the delegate used to declare the event.

    Events also could be wired into each control that needs to know about them (look up multicast delegates), so you could do something like:

    this.form_staffinfo.StaffIdChangedEvent += this.some_method_on_page;
    this.form_staffinfo.StaffIdChangedEvent += this.some_control_on_the_page;
    this.form_staffinfo.StaffIdChangedEvent += this.some_other_control_on_the_page;
    

    In any event, I generally preferred to do this type of wiring in the page’s OnInit method.

    override protected void OnInit(EventArgs e)
        {
            base.OnInit(e);
            InitializeComponent();
        }
    

    and just write your own InitializeComponent method to centralize any of this wiring you have to do.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm making a simple page using Google Maps API 3. My first. One marker
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

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.