触发内部的UpdatePanel一个按钮与一个LoginView [英] Trigger a button inside a UpdatePanel with a LoginView
问题描述
我一个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);
这篇关于触发内部的UpdatePanel一个按钮与一个LoginView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!