Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
640
How to Call Validating Event in Button Click Event
posted

Hi Everyone 

How to fire a Ultratextbox validating event in Ultrabutton Click event. I tried it usually like these following two methods both throws same errors like this

Method 1:

private void uiButton1_Click(object sender, EventArgs e)

{

uiTextBox_Validating(this, CancelEventArgs.Empty);

}

Method 2:

private void uiButton1_Click(object sender, EventArgs e)

{

uiTextBox_Validating(this, e);

}

It throws some errors like

Error 2 The best overloaded method match for 'Task_2_Control_Panel.FrmControlPanel.uiTextbox_Validating(object, System.ComponentModel.CancelEventArgs)' has some invalid arguments D:\Task 2 Control Panel\Control Panel.cs 1225 13 Task 2 Control Panel

Error 3 Argument '2': cannot convert from 'System.EventArgs' to 'System.ComponentModel.CancelEventArgs' D:\Task 2 Control Panel\Control Panel.cs 1225 44 Task 2 Control Panel

Could anyone help me to sort this issue.

Thanks in advance

Ferdin

  • 5
    posted

    I too had the same problem when I tried to fire a validating event within a ButtonClick event.I went through the reply answer to ur post.But answer is not clear to me as well

    ferdin said:

    Hi Everyone 

    How to fire a Ultratextbox validating event in Ultrabutton Click event. I tried it usually like these following two methods both throws same errors like this

    Method 1:

    private void uiButton1_Click(object sender, EventArgs e)

    {

    uiTextBox_Validating(this, CancelEventArgs.Empty);

    }

    Method 2:

    private void uiButton1_Click(object sender, EventArgs e)

    {

    uiTextBox_Validating(this, e);

    }

    It throws some errors like

    Error 2 The best overloaded method match for 'Task_2_Control_Panel.FrmControlPanel.uiTextbox_Validating(object, System.ComponentModel.CancelEventArgs)' has some invalid arguments D:\Task 2 Control Panel\Control Panel.cs 1225 13 Task 2 Control Panel

    Error 3 Argument '2': cannot convert from 'System.EventArgs' to 'System.ComponentModel.CancelEventArgs' D:\Task 2 Control Panel\Control Panel.cs 1225 44 Task 2 Control Panel

    Could anyone help me to sort this issue.

    Thanks in advance

    Ferdin

    ....

     

  • 69832
    Offline posted

    The Form class exposes a method, 'ValidateChildren', which triggers the Validating event for each child of the form. If you want to call the event handler directly, you should not use CancelEventArgs.Empty, but rather a new instance of CancelEventArgs, because the static Empty property is inherited from the System.EventArgs class, and you need a strongly-typed CancelEventArgs instance to call the event handler directly. Also, the value of the 'sender' parameter should probably be uiTextBox, not this, in case the handler logic is expecting the sender to be of a specific type.