Last post Nov 11, 2019 09:20 AM by Brando ZWZ
Nov 10, 2019 11:38 AM|Bjarked|LINK
I have just started working with the ASP.net framework for a school project, so am very new to how it all works. I have tried to reading other post, but i have not been able to figure it out.
What i want to do: I have div which works as a pop up box, which needs to pop up after the user presses a button.
How i have tried to do it:
<div id="TwoFactorPopUp" name="TwoFactorPopUp" runat="server">
HtmlGenericControl popup = new HtmlGenericControl("TwoFactorPopUp");
popup.Attributes["class"] = "hidden";
Edit: i have tried with debugs, and it seems like popup does not contain anything, tried and print id and inner html, and it just prints an empty line
Nov 10, 2019 05:33 PM|PatriceSc|LINK
The first part shows how to create a control inside an ASPX page. Then you show how to create a control by code. For now it seems you perhaps create another control by code that you don't use and so the code doesn't have any effect?
If properly defined in your ASPX page your code could be just TwoFactorPopUp.Attributes["class"]="hidden"; to change the existing control (rather tthen creating a new one you don't use).
The id property is used to expose your "runat" control as a page member so that your server side code can interact with controls defined as part of your ASPX page.
Nov 10, 2019 06:09 PM|Bjarked|LINK
Okay, so just to make sure i understand. Having given my Div both runat="server" and an ID, i should be able to just refer to that object with the ID name ? Because when i try and just write TwoFactorPopUp.Attributes["class"]="hidden",
i get a TwoFactorPopUp does not exist in the current context. So i'm guessing there is something am missing ?
Nov 10, 2019 08:05 PM|PatriceSc|LINK
You are using Visual Studio ? In addition to the "mypage.aspx" file, you should have a "mypage.aspx.designer.cs" file which is created automatically and contains C# declaration for controls found in your page...
Another option might be to not use Web Forms for new applications. (this is part of ASP.NET 4.x) ASP.NET Core is a cross platform rewrite and uses rather
https://docs.microsoft.com/en-us/aspnet/core/tutorials/razor-pages/razor-pages-start?view=aspnetcore-3.0&tabs=visual-studio or MVC.
Nov 11, 2019 09:20 AM|Brando ZWZ|LINK
Could you please post the details aspx codes and the code-behind make up? Do you add the TwoFactorPopUp dynamically in the page load event?
Besides, I suggest you could try to use Page. Find Control(String) method to find the div by id to achieve your requirement.