By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,274 Members | 937 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,274 IT Pros & Developers. It's quick & easy.

Simple problem: Rebinding DropDownList After More Data Entered on Separate aspx Web Form

P: n/a
I have this simple scenario.

--------
Choose an item ->dropdownlist-> or <a>Create a new item</a>

--------

When someone decides to click on the create a new item link, it takes
them to a page in which they can enter more records to the database
field to which the dropdownlist is bound.

Then they close this page. And they are again looking at the
dropdownlist. However, I want their newly created data to be present
in the dropdownlist after they close the enter-more-data page.

HOW!!!?!

I'm simply trying to react to a client envet of them closing this
window created by an <asp:HyperLink> link, and then having that event
trigger another DataBind of the dropdownlist on the original page.
Coordinating a client event with a code-behind method is proving
difficult.

Please help.
Thanks,
Keith
Nov 18 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
You can use JS on the AddNewItems.aspx page which opens in a new window to control the page which opened it (The parent page which contains the Bound DropDownList). So when you click on the <asp:HyperLink /> on AddNewItems.aspx page, JS code is fired that re-direct the parent window to itself, and this would cause the data to be re-bound

[AddNewItems.aspx
<asp:HyperLink
id="HyperLink1"
runat="server"
NavigateUrl="javascript:window.opener.location = 'BoundDropDownListPage.aspx';"
Close Add Items Windo
</asp:HyperLink

Also rather than

javascript:window.opener.location = 'BoundDropDownListPage.aspx'

You can also try, but this may cause problems if you have already PostedBack the parent page

javascript:window.opener.location.reload()

Rasika Wijayaratne
Nov 18 '05 #2

P: n/a
<asp:HyperLink
id="HyperLink1"
runat="server"
NavigateUrl="javascript:window.opener.location = 'BoundDropDownListPage.aspx';"
Close Add Items Windo
</asp:HyperLink

You can add window.close(); to the above to close the opened window as well

<asp:HyperLink
id="HyperLink1"
runat="server"
NavigateUrl="javascript:window.opener.location = 'BoundDropDownListPage.aspx';window.close();"
Close Add Items Windo
</asp:HyperLink

Rasika Wijayaratne
Nov 18 '05 #3

P: n/a
Thanks for your reply.

Let me try to clear this up somewhat for the both of us.

- First, if I could do this all without client-script, I'd
be happy to (do it all in the code-behind of the two linked .aspx pages).

- Second, what exactly does window.opener.location do?
- Is opener a reference back to the parent window?
- And location? - the new url to be set for the parent window?

- Third, It seems that If I put that
<asp:HyperLink ...>Close Window</asp:HyperLink>
in the crtItems.aspx page, then the user would have to click on
the link to close the window - what if they click the 'x'? Is there
someway I could trigger an 'onClose' (or onUnload) event for the
crtItems.aspx window and call the same javascript code to cover
universal closings of the window?

- Fourth, there are other DropDownLists on the BoundDropDownList.aspx
page, and I'm afraid if reloading it will lose choices of those DDLs
reload those and set the page back into its initial state (in which
some controls are not enabled).

- Fifth, here's a look at some code from the two pages:

[BoundDropDownListPage.aspx]
==============================================
<div id="thisDiv">
<span id="step1">1. Choose an Item from the DropDownList</span>
<asp:dropdownlist id="ddlItems" runat="server" AutoPostBack="True" />
<asp:hyperlink id="hlCrtItems" runat="server" NavigateUrl="crtItems.aspx"
Target="_blank">or Create New Item</asp:hyperlink>
</div>

[BoundDropDownListPage.aspx.vb]
==============================================
Sub BindItemsDDL()
... ' Code to open the connection, pull from DB, and bind to DDL
... ' Called when a previous page event (or DDL change) occurs
End Sub

[crtItems.aspx]
==============================================
<div>
<span>1. Enter Item One</span>
<asp:textbox id="txtItem1" runat="server"/>
<asp:requiredfieldvalidator id="rfvtxtItem1" runat="server"
Text="Required Field!" ControlToValidate="txtItem1"/>
</div>
<asp:Button ID="btnSubmitNewItem" runat="server" Text="Submit New Item" />

[crtItems.aspx.vb]
==============================================
Private Sub btnSubmitNewLab_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnSubmitNewLab.Click
... ' An insert SQL stmt, new command, open conn, execute cmd, close conn
End Sub
Nov 18 '05 #4

P: n/a
Unfortunately, there's no way for the server to initiate the contact with
the client so once page1 has been rendered, anything that happens in page2,
such as a hyperlink click, can't be passed by the server back to page1.

One way in which I have accomplished similar tasks in the past is to use Web
Dialogs. When the user clicks the appropriate "add" button in the web
dialog:
Pass the information to the parent page,
Set hidden form field values in javascript,
Submit the form programmatically,
DataBind the drop-down list again at that time.

In the case of error or failure to add, you can set a client side variable
that is checked on page load and re-open the web dialog again if necessary
when the page loads.

In a fast intranet situation it works very well. On dial-up, auto postback
of any kind sucks!

Dale

"Keith" <Th**********@comcast.net> wrote in message
news:6c**************************@posting.google.c om...
I have this simple scenario.

--------
Choose an item ->dropdownlist-> or <a>Create a new item</a>

--------

When someone decides to click on the create a new item link, it takes
them to a page in which they can enter more records to the database
field to which the dropdownlist is bound.

Then they close this page. And they are again looking at the
dropdownlist. However, I want their newly created data to be present
in the dropdownlist after they close the enter-more-data page.

HOW!!!?!

I'm simply trying to react to a client envet of them closing this
window created by an <asp:HyperLink> link, and then having that event
trigger another DataBind of the dropdownlist on the original page.
Coordinating a client event with a code-behind method is proving
difficult.

Please help.
Thanks,
Keith

Nov 18 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.