This article will show you how you can show hide div control
from code behind using c#.net in asp.net.
Some of my previous articles as follows: Add
Remove Or Change Css Class Using jQuery In Asp.Net, Disable
And Enable Button Using jQuery In Asp.Net, Nested
GridView Using c#.Net In Asp.Net, Code
to Convert or Writing DataSet Contents Into An XML Data File Using C#.Net In
Asp.Net, Read
XML File in Dataset And Bind To GridView In Asp.Net Using C#.Net, Read
XML File in DataTable and Bind to DataList In Asp.Net Using C#.Net, Cookies
Create, Read and Delete Operation Using jQuery in Asp.Net.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm25.aspx.cs" Inherits="WebApplication2.WebForm25"
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD
XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>c# show
hide div code behind</title>
</head>
<body>
<form id="form1" runat="server">
<div style="background-color:Red;display:none;" runat="server" id="divmsg">
<h4>
C# show hide div code behind </h4>
<br />
</div>
<br />
<asp:Button ID="btnshow" runat="server" Text="Show Div"
onclick="btnshow_Click" />
<asp:Button ID="btnhide" runat="server" Text="Hide Div"
onclick="btnhide_Click" />
</form>
</body>
</html>
|
Now add the below code on button click.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication2
{
public partial class WebForm25 : System.Web.UI.Page
{
protected
void Page_Load(object
sender, EventArgs e)
{
}
protected
void btnshow_Click(object
sender, EventArgs e)
{
divmsg.Style["display"] = "block";
}
protected
void btnhide_Click(object
sender, EventArgs e)
{
divmsg.Style["display"] = "none";
}
}
}
|
Now we have done run the application to check the output.
Excellent
ReplyDelete