Force user control on web page to reinitialize

There are 2 user controls, one of which is inside the other.

These controls are located on .aspx.

One control is a modal popup, the other is a custom search control (the search control is inside a modal popup).

After the user completes the search and closes the form, the next time the pop-up window opens (for the same user), the old values ​​are still present.

How can I clear the values ​​every time a form loads?

Edit: Is it possible to capture a popup close event?

+3
source share
4

, .

, , , , clear.

..., , , ... ! , , .

+2

, , reset . , , Windows #, -. , .

public static void ResetFields(Control.ControlCollection pageControls)
    {
        foreach (Control contl in pageControls) 
        {
            var strCntName = (contl.GetType()).Name;
            switch (strCntName)
            {
                case "Button":
                    contl.Enabled = true;
                    break;
                case "TextBox":
                    var txtSource = (TextBox)contl;
                    txtSource.Text = "";
                    break;
                case "ListBox":
                    var lstSource = (ListBox)contl;
                    lstSource.SelectedIndex = -1;
                    lstSource.Enabled = true;
                    break;
                case "ComboBox":
                    var cmbSource = (ComboBox)contl;
                    cmbSource.SelectedIndex = -1;
                    cmbSource.Enabled = true;
                    break;
                case "DataGridView":
                    var dgvSource = (DataGridView)contl;    
                    dgvSource.Rows.Clear();
                    break;
                case "CheckBox":
                    var chkSource = (CheckBox)contl;
                    chkSource.Checked = false;
                    chkSource.Enabled = true;
                    break;
            }
            ResetFields(contl.Controls);
        }
    }
+3

, JS- , , .

, .

Sys.Application.add_init will not work in this case, since it will only work once when the page is loaded.

You need to write some new JS when the model popup is canceled or closed.

Modifying the control will be your best option, so all other pages using this control can use the new reset functions.

It is difficult to give you more specific information at this time without knowing the structure of your page, usercontrol and any existing javascript.

+1
source

Source: https://habr.com/ru/post/1760156/


All Articles