Updating parent window from popup

M

mkobus

Im relatively new, so please be patient with me...

I need to update a parent .aspx screen from a popup and close the
popup. Normally I would use
'window.opener.location.reload(true);self.close();' but i need the
parent window not to reload or else data that the user has already
entered will be lost during the IsPostBack.

I need the 'Apply' button on the popup to trigger the 'Update' button
on the parent screen. The script ive seen is like this...
'window.opener.location.Form1.Button1.Click(); self.close();' but I
get a Javascript Error that reads
'window.opener.location.Form1.Button1' is null or not an object.

Any thoughts? Ive seen other posts that say to make sure Button1 on
Form1 is within the <form> tags and it is. Any help would be
appreciated!
 
V

Vidar Petursson

Hi

window.opener.document.forms[0].myButton.click();

--
Best Regards
Vidar Petursson
==============================
Microsoft Internet Client & Controls MVP
==============================
 
M

Marina

Maybe something like: window.opener.document.Form1.Button1.click()

Worse case, create a javascript function in the parent that causes the
button to click, and call the function from your child window.
 
M

Marina

That's a little different then actually causing the click event of a button.
If you submit the form, how do you know server side which button submitted
it? I don't think the right button click event handler would be able to run.
 
P

Paul Hobbs

Hi Saravana,

I have looked at your article and the popup calendar works perfectly.
Thankyou! But, I am having a problem using it in a datagrid.

I can place the CalendarUserControl in the ItemTemplate of the datagrid, and
it works as expected when I am editing a particular row of the grid. But, I
am having difficulty binding the user control so that it displays the
current value of that field.

For example, the datagrid is bound to a table of customers, and one column
is the customer's birthday. When the page loads, all the birthdays are
displayed. When I click Edit, I want the CalendarUserControl to show the
birthday for the customer in that row. But at the moment, it is just blank.

Any advice you can give would be greatly appreciated.

Cheers,

Paul Hobbs

PS: I downloaded the source code from your article below, and the datagrid
example doesn't work because the zip file doesn't include the Products.xml
file. Are you perhaps able to create a datagrid example that uses your
CalendarUserControl, but where the datagrid is bound to NorthWind.Orders,
and the CalendarUserControl is bound to Orders.RequiredDate. ;-)
 
S

Saravana

Hi paul,

I tried in datagrid, it is working fine for me. I didnt send the
products.xml with my source code if you want i will send it to you. you
place it in d:\ or change the source code to read that file from specific
location. Use "TextValue" property of the user control to set the default
value for Calendar control. If you want more detail on this, get back to me.

--
Saravana
Microsoft India Community Star,
MCAD,SE,SD,DBA.

PS: I have sent products.xml to your personal account
 
P

Paul Hobbs

Hi Saravana,

I actually managed to solve this problem by using a technique in another of
your articles
(www.microsoft.com/india/msdn/articles/SolutionstoTopFourQuestions.aspx). I
simply borrowed the same technique for preselecting an item in a DDL, and
applied it to the textfield property of the user control, and it works like
a charm.

BUT, I have a new error now!

I have included my code for the ItemDataBound event below:

This code works fine, until I click the Update button in the datagrid, and
then I get an error

Private Sub grdAlbums_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles
grdAlbums.ItemDataBound

If e.Item.ItemType = ListItemType.EditItem Then

Dim drv As DataRowView = CType(e.Item.DataItem, DataRowView)

'get current values

Dim currentArtist As String = CType(drv("ArtistName"), String)

Dim currentDate As String

If drv("AlbumReleaseDate") Is DBNull.Value Then

currentDate = ""

Else

currentDate = CType(drv("AlbumReleaseDate"), String)

End If

'preselect correct item in DDL

Dim ddl As DropDownList

ddl = CType(e.Item.FindControl("lstArtists_edit"), DropDownList)

ddl.Items.FindByText(currentArtist).Selected = True

'set value of text field in Calendar control

Dim ucCal As CalendarUserControl

ucCal = CType(e.Item.FindControl("calRelDate_edit"), CalendarUserControl)

ucCal.TextValue = currentDate

End If

End Sub

This code works fine when I click the Edit button. But after I edit a
field, and click the Update button, I get this error:

Object reference not set to an instance of an object.

And the line of code that trips the error is this:
Line 336: ddl.Items.FindByText(currentArtist).Selected = True

I think I know why this is happening (when the grid goes back to display
mode, the DDL object no longer exists), but I don't know how to fix it.

Thanks for your help!

Cheers,

Paul
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top