[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Using Javascript to force Postback on opening page

Posted on 2004-11-04
15
Medium Priority
?
2,312 Views
Last Modified: 2010-04-30
Page 1 opens a modal dialog, Page 2, using showModalDialog.  When Page 2 closes it passes some data back to Page 1 and then closes.  (code below).  How can I get Page 2 (modal dialog) to make Page 1 (the opening page) do a postback?

Here's the code from Page 2:
Dim sScript As String
            sScript = "<script language=javascript> "
            'sScript += " dialogArguments.location.href = 'memAddAddress.aspx'; "
            sScript += " var pwid = window.dialogArguments.document.all;"
            sScript += " pwid('ucCompany:txtCompany').value='" + txtCompany + "';"
            sScript += " window.close();"
            sScript += "</script>"
            Page.RegisterStartupScript("ClosePage", sScript)
0
Comment
Question by:thespiceman
14 Comments
 
LVL 18

Expert Comment

by:tusharashah
ID: 12497208
Add following line before you close popup in your code and see:

  sScript += "window.opener.location = YourParentPage.aspx;";

-tushar
0
 
LVL 18

Expert Comment

by:tusharashah
ID: 12497280
CORRECTION:

 sScript += "window.opener.location = 'YourParentPage.aspx';"

Those little ' ' are required

-tushar
0
 

Author Comment

by:thespiceman
ID: 12497467
I get the following errer:  'window.opener' is null or not an object
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:thespiceman
ID: 12497496
I get the following error:  'window.opener' is null or not an object.  This is because I did not open the window using window.open but instead use window.showModalDialog.
0
 
LVL 18

Expert Comment

by:tusharashah
ID: 12497499
How exactly are you opening your 2nd page?
0
 

Author Comment

by:thespiceman
ID: 12497560
Here's how...
Dim sCommand As String = "<script language=javascript>window.showModalDialog('Validation.aspx',window,'dialogHeight:600px;dialogWidth:630px;scrollbars:no;help:no;status:no');</script>"
 Page.RegisterStartupScript("memAddressValidation", sCommand)
0
 
LVL 15

Expert Comment

by:praneetha
ID: 12497579
0
 

Author Comment

by:thespiceman
ID: 12497686
tusharashah,
This causes a refresh of the page but not a postback.
 sScript += " dialogArguments.location.href = 'memAddAddress.aspx';"
0
 
LVL 18

Expert Comment

by:tusharashah
ID: 12497723
Try to use following line:

sScript += "window.dialogArguments.location.reload(true);"

-tushar
0
 

Author Comment

by:thespiceman
ID: 12498089
It kind of works.  It does cause the page to postback...BUT...
first I get the error:  The page cannot be refreshed without resending the information.  Click retry to send the information again...

I click Retry and the page does do a postback but the new values that I have loaded in the textboxes ( sScript += " pwid('ucCompany:txtCompany').value='" + txtCompany + "';") are not present
0
 
LVL 18

Expert Comment

by:tusharashah
ID: 12498324
You must be posting or saving some hidden fields on your Parent page. Is it possible to avoid that? & if not then how about passing txtCompany as QueryString and refresthing the page?

 sScript += " dialogArguments.location.href = 'memAddAddress.aspx?Company" + txtCompany + "';"

-tushar
0
 

Author Comment

by:thespiceman
ID: 12499249
That won't work for me.  This page can be called from many different places (via a user control) so it has to be as generic as possible.  I do have it working by doing:  
 sScript += " pwid('btnAdd').click();"

This will work but I will have to change 6+ calling pages.  I would like to find a more 'generic' solution.
0
 

Author Comment

by:thespiceman
ID: 12500083
I've figured out a solution.  I am forcing a postback by the the following:

sScript += " var pwid = window.dialogArguments.document.all;"
sScript += " pwid('" + Session("AddressSubmitName") + "').click();"
0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 12752259
PAQed with points refunded (500)

modulo
Community Support Moderator
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses
Course of the Month18 days, 3 hours left to enroll

831 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