protected void Page_Load(object sender, EventArgs e)
        { //怎样自动点击这个按钮Login1控件里的LoginButton呢?
 
        }

解决方案 »

  1.   

    Login控件有一些比较重要事件:
    LoggingIn:身份验证前触发
    LoggedIn:身份验证后触发
    LoginError:登录失败时触发
    Authenticate:验证身份时触发,如果自定义这个事件处理程序,则系统将取消自动验证,将验证工作交给这个事件处理程序
      

  2.   

    .net 里的控件好像是给它自带的服务器用的,也就是说按钮动作没法修改。不过你可以吧login控件转换为模板,这样按钮单击动作就可以你自己编辑了。自动点击你可以直接调用按钮的点击调用的方法。不必非要找到按钮。
      

  3.   

    protected void Login1_Authenticate(object sender, AuthenticateEventArgs e){string str = WebConfigurationManager.ConnectionStrings["LocalSqlServer"].ConnectionString;SqlConnection conn = new SqlConnection(str);conn.Open();SqlCommand cmd = conn.CreateCommand();cmd.CommandText = "select count(*) from login where username = @u and password = @p";SqlParameter param;param = new SqlParameter("@u", Login1.UserName);cmd.Parameters.Add(param);param = new SqlParameter("@p",Login1.Password);cmd.Parameters.Add(param);int n = (int)cmd.ExecuteScalar();conn.Close();if (n > 0)e.Authenticated = true;elsee.Authenticated = false;}
      

  4.   

    我使用的是AD认证,不是SQL。
    只想自动点击这个登录按钮,或者根据给出的URL自动认证,比如:http://compamy.local/login.aspx?user=zhao&password=123请高手执教。
      

  5.   

    不知道是不是你想要的http://topic.csdn.net/u/20100222/12/62d3f25f-5973-4b45-af7d-5c05dacac830.html
      

  6.   


    protected void Page_Load(object sender, EventArgs e) 

        this.LoginButton_Click(this.LoginButton,EventArgs.Empty);
    }
      

  7.   

    LoginButton_Click并不存在!
    'Logon.Default' does not contain a definition for 'LoginButton_Click' and no extension method 'LoginButton_Click' accepting a first argument of type 'Logon.Default' could be found (are you missing a using directive or an assembly reference?)
      

  8.   


    protected void LoginButton_Click(object sender, EventArgs e)
    {}
      

  9.   


    <asp:Login ID="Login1" runat="server">
            <LayoutTemplate>
                <table border="0" cellpadding="1" cellspacing="0" 
                    style="border-collapse:collapse;">
                    <tr>
                        <td>
                            <table border="0" cellpadding="0">
                                <tr>
                                    <td align="center" colspan="2">
                                        登录</td>
                                </tr>
                                <tr>
                                    <td align="right">
                                        <asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">用户名:</asp:Label>
                                    </td>
                                    <td>
                                        <asp:TextBox ID="UserName" runat="server"></asp:TextBox>
                                        <asp:RequiredFieldValidator ID="UserNameRequired" runat="server" 
                                            ControlToValidate="UserName" ErrorMessage="必须填写“用户名”。" ToolTip="必须填写“用户名”。" 
                                            ValidationGroup="Login1">*</asp:RequiredFieldValidator>
                                    </td>
                                </tr>
                                <tr>
                                    <td align="right">
                                        <asp:Label ID="PasswordLabel" runat="server" AssociatedControlID="Password">密码:</asp:Label>
                                    </td>
                                    <td>
                                        <asp:TextBox ID="Password" runat="server" TextMode="Password"></asp:TextBox>
                                        <asp:RequiredFieldValidator ID="PasswordRequired" runat="server" 
                                            ControlToValidate="Password" ErrorMessage="必须填写“密码”。" ToolTip="必须填写“密码”。" 
                                            ValidationGroup="Login1">*</asp:RequiredFieldValidator>
                                    </td>
                                </tr>
                                <tr>
                                    <td colspan="2">
                                        <asp:CheckBox ID="RememberMe" runat="server" Text="下次记住我。" />
                                    </td>
                                </tr>
                                <tr>
                                    <td align="center" colspan="2" style="color:Red;">
                                        <asp:Literal ID="FailureText" runat="server" EnableViewState="False"></asp:Literal>
                                    </td>
                                </tr>
                                <tr>
                                    <td align="right" colspan="2">
                                        <asp:Button ID="LoginButton" runat="server" CommandName="Login" 
                                            onclick="LoginButton_Click" Text="登录" ValidationGroup="Login1" />
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                </table>
            </LayoutTemplate>
        </asp:Login>
      

  10.   

    ding                  v         
      

  11.   

    protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
    {
    }
      

  12.   

    我想用cookies来实现制动登录的功能,就像开心或者很多的网站都有这样的功能。
      

  13.   


    那个需要在设计窗口点击鼠标右键,选择“将控件转换为模板”,就可以看到源代码。然后,在后台可以这样触发按钮:var btn = this.Login1.FindControl("LoginButton") as IPostBackEventHandler;
    if (btn != null)
        btn.RaisePostBackEvent(string.Empty);
      

  14.   

    当然,你也可以自定义这个控件:using System.Web.UI.WebControls;public class MyLogin : Login
    {
        public void ExecuteLogin()
        {
            this.OnBubbleEvent(this, new CommandEventArgs("Login", string.Empty));
        }
    }用这个自定的的Login控件取代原来的Login控件,就可以使用扩展了的ExecuteLogin方法了。
      

  15.   


    多谢,但是我这么做了,但是运行的时候报错:
            protected void Page_Load(object sender, EventArgs e)
            {
                           var btn = this.Login1.FindControl("LoginButton") as IPostBackEventHandler;
                if (btn != null)
                    btn.RaisePostBackEvent(string.Empty);        }
    Invalid postback or callback argument.  Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page.  For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them.  If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.我于是添加了:EnableEventValidation="false", 错误倒是没有了,但是也没有实现我要的自动点击功能啊?没有作用。
      

  16.   

    楼主,给你完整的代码
    aspx文件:<%@ Page Language="C#" AutoEventWireup="true" CodeFile="TestLogOn.aspx.cs" Inherits="TestLogOn" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <script type="text/javascript">
        
          function pageLoad() {
          }
        
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:ScriptManager ID="ScriptManager1" runat="server" />
            
            <asp:Login ID="Login1" runat="server">
                <LayoutTemplate>
                    <table border="0" cellpadding="1" cellspacing="0" 
                        style="border-collapse:collapse;">
                        <tr>
                            <td>
                                <table border="0" cellpadding="0">
                                    <tr>
                                        <td align="center" colspan="2">
                                            登录</td>
                                    </tr>
                                    <tr>
                                        <td align="right">
                                            <asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">用户名:</asp:Label>
                                        </td>
                                        <td>
                                            <asp:TextBox ID="UserName" runat="server"></asp:TextBox>
                                            <asp:RequiredFieldValidator ID="UserNameRequired" runat="server" 
                                                ControlToValidate="UserName" ErrorMessage="必须填写“用户名”。" ToolTip="必须填写“用户名”。" 
                                                ValidationGroup="Login1">*</asp:RequiredFieldValidator>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td align="right">
                                            <asp:Label ID="PasswordLabel" runat="server" AssociatedControlID="Password">密码:</asp:Label>
                                        </td>
                                        <td>
                                            <asp:TextBox ID="Password" runat="server" TextMode="Password"></asp:TextBox>
                                            <asp:RequiredFieldValidator ID="PasswordRequired" runat="server" 
                                                ControlToValidate="Password" ErrorMessage="必须填写“密码”。" ToolTip="必须填写“密码”。" 
                                                ValidationGroup="Login1">*</asp:RequiredFieldValidator>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td colspan="2">
                                            <asp:CheckBox ID="RememberMe" runat="server" Text="下次记住我。" />
                                        </td>
                                    </tr>
                                    <tr>
                                        <td align="center" colspan="2" style="color:Red;">
                                            <asp:Literal ID="FailureText" runat="server" EnableViewState="False"></asp:Literal>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td align="right" colspan="2">
                                            <asp:Button ID="LoginButton" runat="server" CommandName="Login" 
                                                onclick="LoginButton_Click" Text="登录" ValidationGroup="Login1" />
                                        </td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                    </table>
                </LayoutTemplate>
            </asp:Login>
            
           
            
        </div>
        </form>
        
    </body>
    </html>
      

  17.   

    cs文件using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;public partial class TestLogOn : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            this.LoginButton_Click(this.FindControl("LoginButton"), EventArgs.Empty);    }
       
        protected void LoginButton_Click(object sender, EventArgs e)
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "", "alert('点击了LoginButton');", true);
        }
    }
      

  18.   

    这个按钮虽然被点击了,但是并没有实现登录功能阿?
    我的DestinationPageUrl设的是Default.aspx,如果成功登陆(手动点击),将被转移到Default.aspx。可是楼上的代码只是弹出对话框:'点击了LoginButton',并没有实现登录功能阿?