Communication between two pages to allow a popup to select Customer ID - c#

I have a purchases form that requires you to select a customer ID, currently it is just a dropdown list of Customer Names with their ID hidden.
What I want to do is instead of a dropdown list, there will be a hyperlinked select button that when clicked will open a popup box that allows them to search through a list of customers using whatever field they choose.
Now I have had no problem with making the popup box search through for a customer, I just don't know how to pass that data back to the main page. Are there any examples for this?

There are some ways to send data from popup window to opener window:
1) use window.opener property in popup window:
function pick(data) {
if (window.opener && !window.opener.closed)
window.opener.document.anyForm.anyInput.value = data;
window.close();
}
2) More exotic: use local storage to handle custom events from other window
look at sample

Related

Passing class object to second window wpf

I've searched around online quite a bit and have come up short. How can I pass an instance of a class object to a second popup window and return the changes only if the user clicks ok.
For example say you have a list of people and when you double click a person in the list an edit window appears. In the edit window would be a textbox displaying the person's name where users could change it. The change would only be committed back to the main view model if the user hits the 'OK' button. Otherwise the changes would be dismissed. Ideally this edit window would be modal.
How can I do this?
Let's say you have a person object that you want to modify called Joe so: public Person Joe = new Person(); When you create your new window just say NewWindow window = new NewWindow(Joe);. Then in your NewWindow Constructor let it accept a person object like so
Person aPerson;
NewWindow(Person inPerson)
{
aPerson = inPerson
}
Now when the user clicks on the save button modify whatever fields of aPerson that you need to modify. You can use something like an event to send it back to the original view. Would have put this in a comment, but the code blocks make it easier to read.

problem in opening next form on button click

i've two groups of radio buttons, a drop down list & a submit button..on corresponding selected radio buttons & drop down item i need to open next specific form..
say if i selected in first radio button say Existing user(of website) and in another say individual, and in drop down if i select residential property then it should open a residential form,if i select commercial property then it should open a commercial form etc.
can u please help me out??
I assume there is button and on click of this button you have open either of the forms.. You can add a Button_Click() event handler and in there check
Psuedo-code looks like this
if(radioButton1.selected && dropdownList.SelectedValue =="Residential")
{
frmResidential frmRes = new frmResidential();
frmRes.Show();
}
Code example in previous post will work for window forms. Looks like you have Web Application. In this case you can use Response.Redirect method to go to different web form.
if(radioButton1.selected && dropdownList.SelectedValue =="Residential")
{
Response.Redirect("YouPage.aspx");
}

Creating a modal window with a Date Picker in C#

I have a C# application in which a function is performed which requires a date. The original specification said that the current date could always be used, but now I have to allow for the user to be able to change the date on demand.
The problem is, this operation executes completely in the background. There is only a menu item which the user clicks to start the process. So I wanted to add, when the user clicks the menu item, a modal window which asks the user for the date to be used, and returns the date entered. I have not been able to find a way to do this.
Do I need to create a form which has only one item on it - a DatePicker - and design it to look like a modal window? Or is there an existing modal window class which does exactly this?
I don't think there is a modal window built into the framework.
You will have to create a new windows form. Put a datepicker on it. Make its modifier public and do something like this:
private void MenuItemClick(objec sender, EventArgs e)
{
var userEnteredDate = DateTime.MinValue;
FormWithDate fmNewFormWithDateOnIt = new FormWithDate();
fmNewFormWithDateOnIt.ShowDialog();
userEnteredDate = fmNewFormWithDateOnIt.dtTimePickerOnForm.Value;
fmNewFormWithDateOnIt.Dispose()
//Do your thing
}
UPDATE: You could put a button on the form and set its DialogResult = OK and then do the following:
if (fmNewFormWithDateOnIt.ShowDialog() == DialogResult.OK) //Not clicked the red close button on the form
{
userEnteredDate = fmNewFormWithDateOnIt.dtTimePickerOnForm.Value;
}

How can I transfer information to another form without using static forms?

I have a Windows form that's generated using code (including buttons and what not). On it, amongst other things, there is a text box and a button. Clicking the button opens a new Windows form which resembles an Outlook contact list. It's basically a data grid view with a few options for filtering. The idea is that the user selects a row in this home-made contact book and hits a button. After hitting that button, the (second) form should close and the email address the user selects should be displayed in the text box on the first form.
I cannot use static forms for this purpose, so is there any way to let the first form know the user has selected something on the second firm? Can you do this with events, or is there another way? Mind that I hardly know anything about delegates and forms yet.
Please advise.
Edit 1 = SOLVED
I can return the email address from the second form to the first form now, but that brings me to another question. I am generating controls and in that process I'm also generating the MouseClick eventhandler, in which the previous procedure for selecting a contact is put.
But how do I, after returning the email address in the MouseClick eventhandler, insert that information into a generated text box? Code to illustrate:
btn.MouseClick += new MouseEventHandler(btn_MouseClick);
That line is put somewhere in the GenerateControls() method.
void btnContacts_MouseClick(object sender, MouseEventArgs e)
{
using (frmContactList f = new frmContactList())
{
if (f.ShowDialog(fPrompt) == DialogResult.Cancel)
{
var address = f.ContactItem;
MessageBox.Show(address.Email1Address.ToString());
}
}
}
That appears separately in the class. So how do I put the email address into a text box I previously generated?
Forms in .Net are normal classes that inherit from a Form class.
You should add a property to the second (popup) form that gets the selected email address.
You should show the popup by calling ShowDialog.
This is a blocking call that will show the second form as a modal dialog.
The call only finishes after the second form closes, so the next line of code will run after the user closes the popup.
You can then check the property in the second form to find out what the user selected.
For example: (In the first form)
using(ContactSelector popup = new ContactSelector(...)) {
if (popup.ShowDialog(this) == DialogResult.Cancel)
return;
var selectedAddress = popup.SelectedAddress;
//Do something
}
In response to my first edit, this is how I solved it. If anyone knows how to make it more elegant, please let me know.
void btnContacts_MouseClick(object sender, MouseEventArgs e)
{
using (frmContactList f = new frmContactList())
{
if (f.ShowDialog(fPrompt) == DialogResult.Cancel)
{
var contact = f.ContactItem;
TextBox tbx = ((Button)sender).Parent.Controls[0] as TextBox;
tbx.Text = contact.Email1Address;
}
}
}
You should keep a reference to your generated TextBox in a variable (private field in your class) and use this instead of looking it up in the Controls array. This way your code would still work even if you some time in the future change the location it has in the array, and you would get a compiler message if you removed that field, but forgot to remove the code that used it.
If the second form is modal, I would recommend that rather than having the first form create an instance of the second form and use ShowModal on it, you should have a Shared/static function in the second form's class which will create an instance of the second form, ShowModal it, copy the appropriate data somewhere, dispose the form, and finally return the appropriate data. If you use that approach, make the second form's constructor Protected, since the form should only be created using the shared function.

WPF/C# Add new style pop up form

Quick question: I have a very busy form going on that I have developed for information about say book records.
I want to design an 'add new book form' that is essentially a pop up to input the info. What is the best way to do this? Use a Usercontrol that is called on a button click or menu click? an entire new form?
Have seen this type of functionality, but never designed it in a pop up have just had user input info on the actual form - and it can get very busy.
Thanks for any help. Cheers!
I'd follow a common UI idiom. Which is, from a menu choose "new". This would popup a modal dialog to accept information about the new book form. I'd use the "Popup" control for this dialog. Within this Popup control, I'd embed the actual input dialog which is implemented as a user control.
The popup control is part of the .Net framework. If you can't see the control in the VS2008 designer, then you can still use it by typing the Popup element directly in the text view of the .xaml file.

Categories