0

我对 ASP.NET ImageButton 控件有疑问。

我想要的是:当我点击图片时,我将被重定向到 Google、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();
    }
4

1 回答 1

0

您可以添加列表视图“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

于 2013-05-13T09:50:48.753 回答