Run button inside UpdatePanel with LoginView

I have an UpdatePanel with LoginView inside, now inside AnonymousTemplate I have a button (btnLogin), the problem is that the Triggers tag does not 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> 

And finally, the error: The control with the identifier 'btnLogin' was not found for the trigger in UpdatePanel 'UpdatePanel2'

+1
source share
2 answers

I think that in this case you may need to add a trigger in the code, for example, on the Pre_Init page; you can access the Triggers property, which provides the Add method.

Anticipating that you also need to find the button in the code, also:

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

This should do the trick:

 var trigger = new PostBackTrigger(); trigger.ControlID = button.UnuiqueID; UpdatePanel2.Triggers.Add(trigger); 
+3
source

I think this is due to the fact that the trigger is only valid when you are not logged in.

The button does not exist if you are logged in.

If you trigger a partial postback in a control inside the panel, you don’t need to use a special trigger from what I remember.

What happens if you choose this as follows:

 <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> </asp:UpdatePanel> 
+1
source

Source: https://habr.com/ru/post/915631/


All Articles