I have an asp.net element (form) with a next button, I want when the user click on the button the first div hide and the second div shows by using a c# code.
-
2Sound like the sort of thing you should be doing in javascript. If you want to do it in c# you will have to do it server side so post back the form basically.– Ben RobinsonAug 20, 2015 at 14:27
-
Do you have search ?– binardAug 20, 2015 at 14:28
-
Why do you want to involve a post-back to the server just to hide an element? Is this WebForms or MVC? What have you tried? Where are you stuck?– DavidAug 20, 2015 at 14:29
-
possible duplicate of How to hide a div from code (c#)– SlappywagAug 20, 2015 at 14:32
-
Ben Robinson yes I want to do it on server side– SaifAug 20, 2015 at 14:34
|
Show 8 more comments
2 Answers
Something like this should do it
markup:
<div id="firstdiv" runat="server"></div>
<div id="seconddiv" runat="server"></div>
C#:
protected void MyButton_Click(object sender, EventArgs e)
{
firstdiv.Visible = false;
seconddiv.Visible = true;
}
You can expand from this as required.
Add runat = "server"
and id
to the <div>
you want to show/hide. Then in the server-side C# code you can hide, like this:
var theDiv = YourDivById as HtmlGenericControl;
if (theDiv != null)
{
theDiv.Style.Add ("Display", "none");
}