[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 473
  • Last Modified:

ASP.NET 2.0 Master Page issue

Hi,

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.

Thanks,

Craig
0
ichikuma
Asked:
ichikuma
  • 4
  • 3
1 Solution
 
raterusCommented:
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?
0
 
ichikumaAuthor Commented:
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,

Craig
0
 
raterusCommented:
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, asp.net 1.x and 2.0 uses a different naming schema, so if you upgrade the code may not work, rather, you should get ASP.net 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!

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
ichikumaAuthor Commented:
raterus,

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.

Craig
0
 
raterusCommented:
I think what is happening is asp.net 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...
0
 
ichikumaAuthor Commented:
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,

Craig
0
 
raterusCommented:
Thanks, glad I could help!
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now