Welcome to Dream.In.Code
Getting Help is Easy!

Join 132,287 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,234 people online right now. Registration is fast and FREE... Join Now!




window.opener inside a Master Page {RESOLVED}

 
Reply to this topicStart new topic

window.opener inside a Master Page {RESOLVED}

PsychoCoder
post 24 Sep, 2008 - 07:49 PM
Post #1


using DIC.Core;

Group Icon
Joined: 26 Jul, 2007
Posts: 8,923



Thanked 118 times

Dream Kudos: 8475

Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions


On a site Im working on I have all pages in a Master Page, of course to help with theming and such. In one of the pages I have made a simple popup calendar. The problem Im having is I keep getting the error

QUOTE

'window.opener.document.forms.form1.StartDate' is null or not an object


Here's the code I use to open the popup calendar

jscript

<a href="java script:void(0);return false;" onclick="window.open('../../Popups/PopCalendar.aspx?type=StartDate','cal','width=250,height=225')">


Here's the code in the PopCalendar.aspx

csharp

protected void Change_Date(object sender, System.EventArgs e)
{
string script = "<script language=\"javas" + "cript\">\r\n";
script += "{\r\n";
script += "if(window.opener && !window.opener.closed)\r\n";
script += "{\r\n";
script += "window.opener.document.forms[\'form1\']." + control.Value + ".value = '" + calcDate.SelectedDate.ToString("MM/dd/yyyy") + "';\r\n";
script += "self.close();\r\n";
script += "}\r\n";
script += "}\r\n";
script += "</" + "script>";
ClientScript.RegisterClientScriptBlock(this.GetType(), "SetDate", script);
}


I tried this experiment in VB.NET and it worked fine (not in a Master Page mind you) and in C# without a Master Page it works just fine. Anyone got any ideas?
User is offlineProfile CardPM

Go to the top of the page

gabehabe
post 25 Sep, 2008 - 03:47 AM
Post #2


Working Girl.

Group Icon
Joined: 6 Feb, 2008
Posts: 5,402



Thanked 94 times

Dream Kudos: 2625

Expert In: Dingleberries

My Contributions


Where are you initialising StartDate? The only time I see it used is when you pass it to the PopCalendar~ It's saying it's null, so you must be passing it before it gets assigned any kind of value.

I don't do ASP, so I could be wrong.

Hope this helps smile.gif
User is offlineProfile CardPM

Go to the top of the page

PsychoCoder
post 25 Sep, 2008 - 04:28 AM
Post #3


using DIC.Core;

Group Icon
Joined: 26 Jul, 2007
Posts: 8,923



Thanked 118 times

Dream Kudos: 8475

Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions


StartDate is the name of the TextBox on the page calling the calendar
User is offlineProfile CardPM

Go to the top of the page

PsychoCoder
post 25 Sep, 2008 - 05:06 AM
Post #4


using DIC.Core;

Group Icon
Joined: 26 Jul, 2007
Posts: 8,923



Thanked 118 times

Dream Kudos: 8475

Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions


Not sure it's the best solution but I solved it. When a page is in a master page a lot of funny crap is appended to the name of the controls. Changing the code in Change_Date to this works:

csharp

protected void Change_Date(object sender, System.EventArgs e)
{
string script = "<script language=\"javas" + "cript\">\r\n";
script += "{\r\n";
script += "if(window.opener && !window.opener.closed)\r\n";
script += "{\r\n";
//here we will use the generated form and control name
//to get around being in a master page
script += "window.opener.document.forms[\'aspnetForm\'].ctl00$center_content$" + control.Value + ".value = '" + calcDate.SelectedDate.ToString("MM/dd/yyyy") + "';\r\n";
script += "self.close();\r\n";
script += "}\r\n";
script += "}\r\n";
script += "</" + "script>";
ClientScript.RegisterClientScriptBlock(this.GetType(), "SetDate", script);
}
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/22/08 01:07AM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month