asp:ImageButton没有按预期工作

本文关键字:工作 ImageButton asp | 更新日期: 2023-09-27 18:13:20

我有一个问题与ASP。. NET ImageButton控件。

我想要的是:当我点击图像时,我会被重定向到谷歌,Facebook或Twitter的登录页面,但这不会发生。这是我的登录页面代码:

<section id="socialLoginForm">
    <h2>Use another service to log in.</h2>
    <uc:OpenAuthProviders runat="server" ID="OpenAuthLogin" />
    <asp:ListView runat="server" ID="providerDetails" ItemType="Microsoft.AspNet.Membership.OpenAuth.ProviderDetails"
         SelectMethod="GetProviderNames" ViewStateMode="Disabled">
         <ItemTemplate>
              <asp:ImageButton ID="Login"  runat="server" Width="40" Height="40" ImageUrl='<%# Item.ExtraData["Icon"] %>' AlternateText="Log in using your <%#: Item.ProviderDisplayName %> account." />
         </ItemTemplate>
         <EmptyDataTemplate>
             <p>There are no external authentication services configured. </p>
         </EmptyDataTemplate>
     </asp:ListView>
</section>

下面是下面的代码:

 public partial class Login : Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        RegisterHyperLink.NavigateUrl = "Register.aspx";
        OpenAuthLogin.ReturnUrl = Request.QueryString["ReturnUrl"];
        var returnUrl = HttpUtility.UrlEncode(Request.QueryString["ReturnUrl"]);
        if (!String.IsNullOrEmpty(returnUrl))
        {
            RegisterHyperLink.NavigateUrl += "?ReturnUrl=" + returnUrl;
        }
    }
    public string ReturnUrl { get; set; }
    public IEnumerable<ProviderDetails> GetProviderNames()
    {
        return OpenAuth.AuthenticationClients.GetAll();
    }

asp:ImageButton没有按预期工作

可以添加列表视图"OnItemCommand"命令Aspx页

 <asp:ListView runat="server" ID="providerDetails" ItemType="Microsoft.AspNet.Membership.OpenAuth.ProviderDetails"
        SelectMethod="GetProviderNames" ViewStateMode="Disabled" OnItemCommand="ListView_OnItemCommand">
        <ItemTemplate>
            <asp:ImageButton ID="Login" runat="server" Width="40" Height="40" ImageUrl='<%# Item.ExtraData["Icon"] %>'
                AlternateText="Log in using your <%#: Item.ProviderDisplayName %> account." CommandName="Login" />
        </ItemTemplate>
        <EmptyDataTemplate>
            <p>
                There are no external authentication services configured.
            </p>
        </EmptyDataTemplate>
    </asp:ListView>

背后的代码
protected void ListView_OnItemCommand(object sender, ListViewCommandEventArgs e)
  {
    if (String.Equals(e.CommandName, "Login"))
    {
     // do what ever you want
    }
  }

来源:http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listview.itemcommand.aspx