触发内部的UpdatePanel一个按钮与一个LoginView按钮、UpdatePanel、LoginView

由网友(满江风月)分享简介:我一个UpdatePanel与LoginView内,目前,AnonymousTemplate里面我有一个按钮(btnLogin),问题是,触发器标签看不到按钮。这里是code:i've an UpdatePanel with a LoginView inside, now, inside the Anonymous...

我一个UpdatePanel与LoginView内,目前,AnonymousTemplate里面我有一个按钮(btnLogin),问题是,触发器标签看不到按钮。 这里是code:

i've an UpdatePanel with a LoginView inside, now, inside the AnonymousTemplate i've a Button (btnLogin), the problem is that the Triggers tag don't see the button. here is the code:

<asp:UpdatePanel ID="UpdatePanel2" runat="server">
    <ContentTemplate>
        <asp:LoginView ID="LoginView1" runat="server">
            <AnonymousTemplate>
                <asp:Button ID="btnLogin" runat="server" Text="Iniciar sesión" 
                            onclick="btnLogin_Click" />
            </AnonymousTemplate>
            <LoggedInTemplate>
                <asp:TextBox ID="txtPassword" runat="server" Text="You're in"/>
            </LoggedInTemplate>
        </asp:LoginView>
    </ContentTemplate>
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="btnLogin" EventName="Click" />
    </Triggers>
</asp:UpdatePanel>

和最后的错误: ID为btnLogin控制找不到在UpdatePanel的'UpdatePanel2

推荐答案

我想你可能要做在这种情况下添加触发在code-落后,比如,在 pre_Init 页面;您可以访问触发器属性,它暴露了一个添加方法。

I think what you might have to do in this case is add the trigger in the code-behind, say, on Pre_Init of the page; you can access the Triggers property which exposes an Add method.

preempting,您还需要找到在code中的按钮,也:

Preempting that you will also need to find the button in the code, too:

var button = LoginView1.FindControl("btnLogin") as Button;

这应该做的伎俩:

var trigger = new PostBackTrigger();
trigger.ControlID = button.UnuiqueID;
UpdatePanel2.Triggers.Add(trigger);
阅读全文

相关推荐

最新文章