首页 > 解决方案 > 错误:在类型中找不到正确签名的 EventHandler“btnLogin_Clicked”

问题描述

我正在尝试在 Xamarin 中创建针对 LDAP 的身份验证。我有 Main.xaml,在其中创建了简单的登录表单 (Entry Placeholder="*Password" IsPassword="True" x:Name="login_password") 按钮 (Button Clicked ="btnLogin_Clicked" Text="Sign in" x:Name ="btnLogin")。Main.xaml.cs 包含 LDAP 连接的代码。我在那里检查凭据并尝试绑定。

不幸的是,我收到此错误:“EventHandler 'btnLogin_Clicked' 在类型 'Main.xaml' 中找不到正确的签名”。

我花了很多时间在这上面,但仍然无法弄清楚我做错了什么。如果有人能帮我解决这个问题,或者给我一些关于我可以在哪里搜索答案的建议,我将不胜感激。

我的一段代码:


public void btnLogin_Clicked(object sender,string login_username, string login_password, System.EventArgs e)
    {


        string searchBase = "dc = it, dc = local";
        string searchFilter = "(amemberOf=ALL)";
        string ldapHost = "7777.. ";
        int ldapPort = 389;
        string loginDN = "dc = it, dc = local";

        /*if username or passworwd fields are empty show an error*/

        if (login_username is null || login_password is null)
        {
             DisplayAlert("Alert", "Please, enter your credentials", "OK");

        }
        else
        {
            /*creating an LDAP instance*/
            using (LdapConnection connection = new LdapConnection())

                /*here we create new ldap connection*/
                try
                {
                    /*connect function will creat socket connection to the server*/
                    connection.Connect(ldapHost, ldapPort);
                    connection.Bind(string.Format("{0}@{1}", loginDN, login_username), login_password);
                    LdapSearchQueue queue = connection.Search(searchBase,
                    LdapConnection.SCOPE_ONE, searchFilter, null, false, (LdapSearchQueue)
                    null, (LdapSearchConstraints)null);
                    LdapMessage message;

                    while ((message = queue.getResponse()) != null)
                    {
                        if (message is LdapSearchResult)
                        {
                            /*display message if connect*/
                             DisplayAlert("" ," logged in ", "OK ");
                        }
                        else
                        {
                            /*if the message is not null but the login was failed*/
                            DisplayAlert("", "Login failed", "OK ");


                        }...

标签: c#xamarinldap

解决方案


Button 的事件处理程序具有签名

public void btnLogin_Clicked(object sender, System.EventArgs e)

你不能只在签名中添加额外的参数


推荐阅读