ASP.NET 2.0 Master Page issue

Posted on 2006-05-17
Last Modified: 2012-05-05

I'm having a master page issue and was wondering if someone could lend a hand to help me understand what is happening.  First, here is the hiarchy of what I'm dealing with:

Master Page
     Content Page
           Wizard Step
                TextEdit Control

The problem is, When I populate the TextEdit control from a javascript popup window, the value isn't retained when I switch between wizard steps.

What I did to verify this, is I created the same scenario without the master page and it worked fine.  It seems to be master page related somehow but I have no idea how to procede.

Any help would be greatly appreciated.


Question by:ichikuma
    LVL 33

    Expert Comment

    Adding a Master Page will modify the ID's of everything in your content page to something funky where the only way JavaScript would work is to know the control's ClientID.  Can you share some code of what you are doing javascript wise?

    Author Comment

    Sure, here is the javascript code I'm using when the button on the popup is pressed.  It essentially, gets the data from the page and sets the textbox data and closes itself:

    string[] fields = selectedValue.Split(new Char[] { ';' });
    string returnScript = "";
    returnScript += "<script language=javascript>";
    returnScript += "window.opener.document.forms['aspnetForm'].elements['";
    returnScript += "ctl00$Header$Wizard1$Requestor";
    returnScript += "'].value = '";
    returnScript += fields[0].ToString();

    returnScript += "';window.opener.document.forms['aspnetForm'].elements['";
    returnScript += "ctl00$Header$Wizard1$RequestorPhone";
    returnScript += "'].value = '";
    returnScript += fields[1].ToString();

    returnScript += "';window.close();";
    returnScript += "<" + "/" + "script>";

    if (!Page.ClientScript.IsClientScriptBlockRegistered("RequestorScript"))
         Page.ClientScript.RegisterStartupScript(typeof(Page), "RequestorScript", returnScript);

    This part actually works fine.  When the window closes, the textboxes on the calling page contain the values.  The problem arises when I move to the next page in the wizard and then back.  When I move back, the data is gone, the wizard isn't persisting the data like it does for a regular textbox.

    Thanks again for your help,

    LVL 33

    Expert Comment

    This might not fix your problem, but it will make your life much easier!

    You should never write stuff like "ctl00$Header$Wizard1$Requestor" in your JavaScript code, it makes it rather difficult to change the layout of your page, because you will constantly have to know stuff like this exists and go and change it.  Also, 1.x and 2.0 uses a different naming schema, so if you upgrade the code may not work, rather, you should get to write this value for you.  You can do this through the ClientID property of the server control.

    Anyway, to your problem,

    I created a test page with two wizard steps, in a masterpage, and it appeared to work great.  I'd try to do this yourself (create a bare-bones page), and see what happens.  If it works, and I think it will, you need to add parts of your existing page, like the javascript, until you figure out what the problem is.  Something is clearing those values, or getting in the way from those values being restored properly!


    Author Comment


    Thanks for the input on the ClientID, I was also looking for a solution to the in another thread.  I will certainly implement it in that way.

    I took your suggestion and this is what I found.  One of the requirements for this particular page is that the user can't type in a name, they must pick the name from the popup window.  So, the textbox is "ReadOnly".  If I remove that flag, then it works as expected.

    I guess you know what I'm going to ask next right?  How can I keep the user from editing the textbox but still have it persist the values from wizard step to wizard step?

    Thanks again, I've been banging my head against the wall all day trying to figure this out.

    LVL 33

    Accepted Solution

    I think what is happening is is trying to be "smart" about the posted value on a readonly textbox, it appears to ignore the value, which probably isn't a bad idea.

    I don't see any way around this, what might work a little better and smoother is to use a Label and a Hidden Input.  Your JavaScript popup populates both a Label's text and a hidden field to the value they select.  When the page is posted back, you grab the value from the hidden field rather than from the textbox, and you will also need to set the label's text to that value (since the label's value you set in javascript isn't persisted yet in the viewstate).

    Technically though, a smart web user could figure out how to "hack" this setup, so if that is a problem, you might need to throw in a customvalidator to check their value against the real DB.

    Just my initial thoughts on it...

    Author Comment

    Thanks raterus.  For now, what I did was, just put some javascript code on the edit box to eat an keystrokes.  That way they can't change anything.  Again, a savey user could probably get over this as well.

    Thanks again for all your help, I will award the points to you.

    Have a great day,

    LVL 33

    Expert Comment

    Thanks, glad I could help!

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Suggested Solutions

    In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
    I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    732 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now