Search code examples
asp.netwebformshidden-field

How can I display a hidden user control in ASP.NET?


I have an aspx page called addcustomer.aspx. The customer can create a new account on this page. There is a button called CREATE ACCOUNT. If the user has created an account before with the same email address, I want to show a popup control called customerexists.ascxwith some options (1) continue creation with a different email address (2) login to the website. For the first option, the user stays on the page and for the second, the user is redirected to login page.

Currently the way I have done is, I have a property called CustomerExists on the user control customerexists.ascx. The addcustomer.aspx checks for the existence of the customer and sets the property CustomerExists. That flag will display some portion of the text on that control. It works.

How can I do this in the control customerexists.ascx itself? I tried in the Page_Load of the control, but nothing happens because the Page has already finished the Page_Load event.


Solution

  • There are many ways to accomplish that:

    • Implement your code in the Control.PreRender event, that's an easy implementation.
    • Implement a public Method in your control, something like Validate, and call that method from your page.