SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2012
    Posts
    46
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to read value/text in a textbox control (<asp:TextBox ID="Text1" runat="server">

    Hello folks,

    I have a small popup widow that gets launched successfully using the following code:

    Code:
     function OpenWindow_HistoricalRuns() {           
                
                var windowIncsimHistRuns = window.open('MVal.aspx', 'Market', 'width=350,height=425,scrollbars=0');
    
                windowIncsimHistRuns.moveTo(500, 300);
    
            }
    When the popup window is launched successfully I am actually storing a value "Market" in a hidden text box as shown below:

    Code:
    function SetDisplay() {
    
                  document.getElementById('<%=TextBoxSourcePageName.ClientID%>').value = window.parent.name;
                 
              }
    Now in the Page_LOad event of the popup window, I want to see what is stored in the hidden text box control (TextBoxSourcePageName). I am using the following asp.net c# code in the Page_load event. But I don't get anything even though the hidden control has the text "Market".

    Code:
     protected void Page_Load(object sender, EventArgs e)
            {
    
                if (!this.IsPostBack)
                {
                    try
                    {
                        if (TextBoxSourcePageName.Text == "MarketVal")
                   }
               }
            }
                        {

  2. #2
    SitePoint Enthusiast
    Join Date
    Jan 2012
    Posts
    46
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think i know the reason for not being able to see the text in TextBoxSourcePageName control.

    When the popup form is loaded, until the code in page_load event is done (finished execution), the SetDisplay function in body tag of the popup window will not be executed. That is whey in the page_load event of the popup form, when i try to read the value of TextBoxSourcePageName control, I don't get anything.

    Now the challenge is how to pass the parameter in a different way then.
    any suggestions?
    thanks

  3. #3
    Avid Logophile silver trophy
    ParkinT's Avatar
    Join Date
    May 2006
    Location
    Central Florida
    Posts
    2,285
    Mentioned
    181 Post(s)
    Tagged
    4 Thread(s)
    In think your problem is with the Javascript "getElementById" call.
    This method finds an HTML element based on its CSS ID. You are passing the method an ASP tag. You need to find the "rendered" HTML tag and call it by that ID.
    Don't be yourself. Be someone a little nicer. -Mignon McLaughlin, journalist and author (1913-1983)


    Literally, the best app for readers.
    Make Your P@ssw0rd Secure
    Leveraging SubDomains

  4. #4
    SitePoint Enthusiast
    Join Date
    Jan 2012
    Posts
    46
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Understood.

    In my situation, I need to know the window.parent.name by the time Page_load event gets triggered on the popup window. Because I have to do some specific thing in the Page_Load event (of popup window), based on window.parent.name.

    So my fundamental question is, which one will get fired first in an .aspx page.

    1. Javascript in the body tag
    or 2. Page_load event?

    If Javascript function in the body tag gets fired first, then by the time I get to Page_Load event, I should already have whatever I need.

    thanks

  5. #5
    SitePoint Enthusiast
    Join Date
    Jan 2012
    Posts
    46
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Got my answer. Thanks


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •