none
How to call a form controls from a non form CS file. RRS feed

  • Question

  • I have a cs file defined behind a ascx file which in tern called in an aspx page. I wanted to show a popup input message box to take user name and password inputs from the user , verify it and then do some actions in my ascx.cs file. I didn't get a single example of this in google. everywhere its written how to call a windows form from another form object.

    my ascx.cs file code is

    protected void btnSubmit_Click(object sender, EventArgs e)
            {
                if (!Page.IsValid)
                    return;
               var contact = new ContactEntity();
                contact.LastName = txtLastName.Text;
                contact.FirstName = txtFirstName.Text;
                contact.Role = ddlRole.SelectedValue;
                contact.EmailAddress = txtEmail.Text;
                _contactUiProvider.CreatePrimaryWebUser(ContactUIProvider.CurrentContact.AccountSelected.AccountId,
                                                        contact.EmailAddress)

    }

    and my form cs file code is 

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;

    namespace Myob.MyDot.UI.UserControls
    {
        public partial class VerifyPassword : Form
        {
            public VerifyPassword()
            {
                InitializeComponent();
            }

            private void VerifyPassword_Load(object sender, EventArgs e)
            {

            }
            public string UserName
            {
                get {
                    return txtUserName.Text;
                }
                set { txtUserName.Text = value; }
            }
        }
    }

    • Moved by Stanly Fan Wednesday, August 22, 2018 1:30 AM
    Tuesday, August 7, 2018 8:50 PM

All replies

  • I have a cs file defined behind a ascx file which in tern called in an aspx page. I wanted to show a popup input message box to take user name and password inputs from the user , verify it and then do some actions in my ascx.cs file. I didn't get a single example of this in google. everywhere its written how to call a windows form from another form object.

    Hi Sahenaz,

    If you want to call a Winform from another project, you need to add the winform project as a reference, then use it as a class:

        VerifyPassword vp = new VerifyPassword();
        string userName = vp.UserName;

    Note: I think your problem is more related to call a project from ASP.NET application, it will be more appropriate to ask your question at ASP.NET Forums.

    Thank you for your understanding.

    Regards,

    Stanly


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, August 8, 2018 2:17 AM