Tuesday, November 11, 2008

ASP.net's "Wizard" wizard control and javascript fun

Alright, so here's where my massive nerdliness comes out. I just worked through a problem and I'm stoked.

More for my own documentation than anything, here's what happened.

I switched an ASP.Net 2.0 form to a Wizard control (named Wizard1, how quaint). However, I still needed to call a pop-up page and have that pop-up page read information from the Wizard page. When I tried this, it didn't work, it couldn't read the controls anymore, even though they were still on the page. Frustrating.

So I end up throwing javascript alerts and digging through what it CAN see, and I found the problem. Somehow the Wizard control makes it seem as if the calling page has multiple pages, and the controls I was trying to read weren't on the page that was calling the pop-up. What I needed to do was to create controls on the 'review' page and populate them with data from the controls on the input page, then have the pop-up read the duplicated controls like so: "window.opener.document.getElementById("Wizard1$txtFullAddr").value". I just had to add the 'Wizard1$' in front of the new controls I made (the duplicated ones) and all was well.

UPDATE:
It turns out that 'getElementByID' doesn't work all the time in FireFox. I had to resort to 'window.opener.document.forms[0].elements["Wizard1$txtEventReview"].value' to get access to my page's controls. Meh. It'll work I guess.

No comments: