Listbox Item, open new browser and add records, can it be done?

J

James Radke

Hello,

If I have a web page which displays dropdownlists containing databound
items, for example employees or something as well as an entry at either the
beginning or end which says "<NEW>"; is there a way that when the user
clicks on the NEW item, a new browser is launched presenting a data entry
screen for all the record details where they can add a new employee record.
Then when they press OK from this screen (i.e. add a new employee record
screen), this second browser window is closed, and the listbox in the
initial screen gets rebound to the dataset; and the added item automatically
selected in the listbox.

Can that be done? If so, does anyone have any examples of how this can
work?

Thanks!

Jim
 
J

Jacob Yang [MSFT]

Hi James,

To my knowledge, I have an idea on how to implement your task for your
reference. ( I have not found an existed sample for this issue. )

1. When <New> was clicked, open a new window by using the
window.ShowModalDialog function.

var returnVal;
returnVal = window.showModalDialog("child2.html");

2. When all the entries in the new modal window and submit button was
clicked, close this modal window and return the new added item to the
parent (here, the parent denotes the window where the dropdownlist was
located),

window.returnValue = "ID & Name of new item";
window.close();

3. In the parent window, we then can add the new item returned from modal
window into the dropdownlist via some javascript. The new item should be
stored in returnVal.

Does it answer your question? If I have misunderstood your concern, please
feel free to let me know.

Best regards,

Jacob Yang
Microsoft Online Partner Support
Get Secure! ¨C www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
J

James Radke

Jacob,

I don't understand how I can execute the javascript function showModalDialog
when a certain item in the listbox is selected? Do I have to have an
OnChange (or something similar) coded for the dropdownlist which calls this
function, then within the function check if the selectedindex is a certain
value?

I don't think I would need to worry about returning the value, as the Modal
..ASPX page would add the record to the database but the javascript would
then have to somehow do a postback calling a specific function on the server
which would do the databind of the dropdownlist control again - can that be
done?

Thanks!

Jim
 
J

Jacob Yang [MSFT]

Hi James,

Thank you for your update.

It is correct that we have to hook the onchange event of the dropdownlist,
and in that hooked javascript function, we should check the value of the
selected item. If it denotes the <New> item, do invoke the
window.showModalDialog method.

As for the return value, of course, we can ignore it. As an alternative, we
can submit the parent aspx page to rebind the dropdownlist when the modal
dialog closed and returned.

Does it answer your question? If I have misunderstood your concern, please
feel free to let me know.

Best regards,

Jacob Yang
Microsoft Online Partner Support
Get Secure! ¨C www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
J

James Radke

Jacob,

Yes, that answers my question... I was wondering, why does a modal dialog
..aspx page (i.e. launched by using the window.showmodaldialog from a
javascript) always postback to a new window different from the original?

Thanks!

Jim
 
J

Jacob Yang [MSFT]

Hi James,

I am very glad to know that my answer is helpful.

By default, the modal dialog will postback to a new window. However, we can
do some changes to make it postback to itself.

1. Firstly, we should assign a name to the modal window at the top of the
web page each time the web page was opened as a modal dialog.

<SCRIPT language=javascript>
// execute this line of code below each time this web page was shown up.
// we can assign any string to the name property.
window.name = "mydialog";
</SCRIPT>

2. Secondly, we should ask the web page to submit to the same window by
pointing the target property on the <Form> tag to the window.name property
we designated above.

<form name="Form1" method=post action="myself.aspx " target=" mydialog">

3. Now each time the web page submits, it will postback to the current
window, rather than opening a new one.

Does it answer your new question? If I have misunderstood your concern,
please feel free to let me know.

Best regards,

Jacob Yang
Microsoft Online Partner Support
Get Secure! ¨C www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 

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,774
Messages
2,569,596
Members
45,135
Latest member
VeronaShap
Top