0

Hi All,

I have created two forms in my Windows Application.

One Form acts as a Form and the other form acts as a MODAL DIALOG BOX.

The Form Dialog Box contains a button and One textBox.
When this button is clicked the MODAL DIALOGBOX should be displayed.
This dialog box also contains One Textbox and Two Buttons(Ok and Cancel).

Now when this dialog box is displayed the TextBox of the dialog box should contain the value entered in the textbox of Form1.

I have used the following coding to accomplish this task.
Form1 Coding:

public string UserName;
        private void btnFn_Click(object sender, EventArgs e)
        {
UserName = txtUserName.Text;
frmFnC objFnC = new frmFnC();
                    objFnC.ShowDialog();
objFnC.txtUserName.Text = UserName;
      }

Code in MODAL DIALOGBOX OK button:

Please note that the Cancel button is enabled only when the OK button is clicked.

Coding:

private void btnOk_Click(object sender, EventArgs e)
        {
         btnCancel.Enabled=true;
}
private void btnCancel_Click(object sender,EventArgs e)
{
this.Close();
}

The problem I am facing is the value entered by the User in the USERNAME textbox is not displayed in the TEXTBOX in the MODAL DIALOG BOX. Instead it is displaying the textbox as empty.


What should I do to get the values entered by the user in the textbox to this modal dialog box?

Can anybody help me out in performing the desired task?

Thanks in advance!!!

2
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by S2009
1

Change the order of statement

objFnC.txtUserName.Text = UserName;
  objFnC.ShowDialog();
Votes + Comments
You have an eye for details.
0

Change the order of statement

objFnC.txtUserName.Text = UserName;
  objFnC.ShowDialog();

Ok

thanks for your prompt reply.

I have achieved the desired result.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.