Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Another Spin on using Popup Windows with ASP.NET

Status
Not open for further replies.

StillLearning

Programmer
Jan 12, 2000
11
US
Hello,
I am a newbie and have been struggling with using popup windows with ASP.NET. I have read several of the posts here and have even searched the internet with no luck. Hopefully, someone can provide an example.

Problem: I have a parent form with a dropdownlist and linkbutton on it. If a user does not see an item in the dropdownlist, they will click the linkbutton to popup a window to enter a new item in the system. After closing the window, the newly entered value should show up in the dropdownlist. Can anyone provide me a sample of how this can be accomplished. I know how to open the child window, but how do I add the new item to the dropdownlist in the parent window. Is it possible without having the user to navigate to another page and refill the parent form?

He/she who does not take note, often forgets. Anderson Phillips III (10/22/01)
 
I hate pop-ups! I have my browser kill them. IE has just introduced a pop-up killer, so you may want rethink your appdesign.
That said, you must keep in mind that all asp.net does is write the web controls to a page. (Of course there is so much more that can be done, but thats the basic idea.) So what you need to do is execute a javascript function that will add the "options" (thats the html term for the dropdownlist) to that control.
Say you never had that pop-up and you wanted to add to that dropdown list the old way (before DOT.NET). You would do the following.
function AddToDDList(obj)
{

obj.options[1]=new Option("Text","value")
}
I think that with [-1] you just add to the end of the option array.

So in short in your POP-UP window have a javascript function that will add to that dropdown box.
(I haven't messed with javascript in a while so check to see if this works)
parent.opener.yourform.your_dd_list.options[index]=new Options("text","value");

I may have missed some syntax, but I hope that you get the idea. The big problem is how to update the system so that next time you will get that menu selection. You could write to a hidden field and when the user posts you use that fields and update the DB.

I hope that I gave you some ideas.
Klaz
 
Still -

Interestingly, that is the next problem I am faced with, to return a value to a dropdown list from a pop up window -indeed I was going to work on that problem tomorrow.

If I get it solved I'll post back with a solution. My intial starting point was to use something like the following javascrip which sends back a value to a textbox on the form, I figured it might work too for a drop down.

function ReturnDate()
{
window.opener.document.forms["<%= strFormName %>"].elements["<%= strCtrlName %>"].value = "<%= strSelectedDate %>";
window.close();
}

 
..and thanks Klaz...there just might be enough info here to find a nice solution to this problem.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top