Muhammad Ibrar Muhammad Ibrar - 1 month ago 5
ASP.NET (C#) Question

Accessing Properties of checkbox from link button of another page in ASP.NET

I am creating a web application using asp.net I'd like to know how to alter properties of a checkbox of one page from another page: Eg: my Page2.aspx page has a checkbox with id checkbox1 and by default its visibility is false. Now i need to set the visibility of checkbox1 to true from another page Page1.aspx with click event of a link button with id linkbutton1.
any help in this regards please?

Answer

You can use this approach also

page1.aspx

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>

<body>
    <form id="form1" runat="server">
    <div>
    <asp:linkbutton ID="Linkbutton1" runat="server" onclick="Linkbutton1_Click">LinkButton</asp:linkbutton>
    </div>
    </form>
</body>
</html> 

page1.aspx.cs

protected void Linkbutton1_Click(object sender, EventArgs e)
    {
        Response.Redirect("page2.aspx?visible=1");//this is how to control the visibility 
    }

and page2.aspx.cs

protected void Page_Load(object sender, EventArgs e)
    {
        //Request.QueryString["visible"].ToString() will be same

        if (Request.QueryString[0].ToString() != "1")
        {
            CheckBox1.Visible = false;
        }
        else
        {
            CheckBox1.Visible = true;
        }
    }
Comments