0
votes

I have a main page: Main.aspx and 2 user controls User1.ascx and User2.ascx. First, i want User2.ascx to be invisible.I have a hidden value in the main page control. And if value of hidden value is not null then show user2.ascx. I have typed the code in the prerender function on user2.ascx.

Currently, what I try

In Main.aspx

<usercontrol:User1 runat="server" ID="user1control" Visible = "false"  />

By this, In User2, it comes only in pageload event but not in OnPreRender.

I have my all code in OnPreRender

2

2 Answers

0
votes

Try something like this

protected void btnToggle_Click(object sender, EventArgs e)
    {
        string s = btnToggle.Text;

        switch (s)
        {
            case "Hide":
                btnToggle.Text = "Show";
                break;
            case "Show":
                btnToggle.Text = "Hide";
                break;
        }
        ucDetails myControl = (ucDetails)Page.LoadControl("~/ucDetails.ascx");
        UserControlHolder.Controls.Add(myControl);
        myControl.Visible = !myControl.Visible;
    }

The other option you can create this on the javascript side. Where you can wrap your usercontrol in a panel and hide and show through javascript function. Hiding and showing through css.

<script type="text/javascript">
    function hide() {
        document.getElementById("ResultPanel2").style.display = 'none';
    }
</script>
0
votes

I Solved it. I kept a hidden field in main page, and in the load event of main page, I kept a contion that if the value is not null or empty then, user2.visible = true. This worked for me.