details

Requirements

Database Table Structure

  1. create table tbl_ModalPopUp_Sample
  2. (
  3. ID int identity primary key,
  4. UserName varchar(50),
  5. Mobile_No bigint
  6. )
Procedure

  1. <asp:ModalPopupExtender ID="ModalPopupExtender1" runat="server"
  2. CancelControlID="btnClose" PopupControlID="ModalBox"
  3. TargetControlID="LinkButton1" BackgroundCssClass="modalBackground"
  4. DropShadow="True">
  5. </asp:ModalPopupExtender>
We must call the ID of the Panel or DIV at the ModalPopUp PopupControlID=" " property that we want to show as the design of the ModalPopUp Control.

CSS Class For ModalPopUp
  1. .modalBackground
  2. {
  3. background-color: #336699;
  4. filter: alpha(opacity=80);
  5. opacity: 0.8;
  6. }
  7. .modalBackground:hover
  8. {
  9. background-color : #CC3300;
  10. }

After adding ModalPopUp

You will find this Page Directive at the page level after adding the ModalPopUp:

  1. <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
Layout of the design

Lay Out Of The Design


Complete Design
  1. <%@ Control Language="C#" AutoEventWireup="true" CodeFile="Modal_Pooup_Control.ascx.cs" Inherits="Ajax_User_Controls_Modal_Pooup_Control" %>
  2. <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
  3. <style type="text/css">
  4. .Clear
  5. {
  6. clear:both;
  7. }
  8. .logButton
  9. {
  10. width: 100px;
  11. height: 30px;
  12. background-color: #FB5F67;
  13. font-family: Arial, Helvetica, sans-serif; font-size: 13px; font-weight: bold; font-style: normal;
  14. font-variant: normal; text-transform: capitalize; color: #FFFFFF;
  15. }
  16. a:hover {color:#FF00FF;}
  17. a:link {color:blue;}
  18. a:visited {color:green;}
  19. a:active {color:yellow;}
  20. input[type="submit"]:hover {
  21. background:#0000FF;
  22. }
  23. .LoginBox
  24. {
  25. margin: 10px;
  26. height: 270px;
  27. background-color: #FB5F67;
  28. }
  29. .Heading
  30. {
  31. margin: 10px;
  32. height: 15px;
  33. background-color: #FFFFFF;
  34. font-family: Arial, Helvetica, sans-serif; font-size: 12px; font-weight: bold; font-style: normal;
  35. font-variant: normal; text-transform: capitalize; color: #6C6B6B;
  36. text-align: center;
  37. padding: 4px;
  38. }
  39. .InnerLogin
  40. {
  41. margin: 10px;
  42. margin-right: 5px;
  43. width: 320px;
  44. height: 250px;
  45. float: left;
  46. background-color: White;
  47. }
  48. .NewUserBox
  49. {
  50. margin: 10px;
  51. margin-left: 5px;
  52. width: 330px;
  53. height: 250px;
  54. float: left;
  55. background-color: White;
  56. }
  57. .ClickButton
  58. {
  59. width: 100px;
  60. height: 30px;
  61. background-color: #339933;
  62. font-family: Arial, Helvetica, sans-serif; font-size: 13px; font-weight: bold; font-style: normal;
  63. font-variant: normal; text-transform: capitalize; color: #FFFFFF;
  64. }
  65. .ContentInside
  66. {
  67. margin: 10px;
  68. }
  69. .TextBoxSize
  70. {
  71. width: 200px;
  72. }
  73. .SmallTextBox
  74. {
  75. width: 100px;
  76. }
  77. .DropDownSize
  78. {
  79. width: 255px;
  80. height: 23px;
  81. }
  82. .ContentMiddle
  83. {
  84. margin: 0px auto;
  85. height: auto;
  86. width: 500px;
  87. }
  88. .LeftHeading
  89. {
  90. font-family: Arial, Helvetica, sans-serif;
  91. font-size: 14px;
  92. font-weight: bold;
  93. font-style: normal;
  94. font-variant: normal;
  95. text-transform: capitalize;
  96. color: #CC3300;
  97. text-align: left;
  98. }
  99. .SubHeadingLeft
  100. {
  101. margin: 10px;
  102. height: 15px;
  103. padding: 4px;
  104. background-color: #999999;
  105. font-family: Arial, Helvetica, sans-serif;
  106. font-size: 12px;
  107. font-weight: bold;
  108. font-style: normal;
  109. font-variant: normal;
  110. text-transform: capitalize;
  111. color: #FFFFFF;
  112. text-align: left;
  113. }
  114. .SmallButton
  115. {
  116. width: 70px;
  117. height: 30px;
  118. background-color: #666633;
  119. font-family: Arial, Helvetica, sans-serif; font-size: 13px; font-weight: bold; font-style: normal;
  120. font-variant: normal; text-transform: capitalize; color: #FFFFFF;
  121. }
  122. .modalBackground
  123. {
  124. background-color: #336699;
  125. filter: alpha(opacity=80);
  126. opacity: 0.8;
  127. }
  128. .modalBackground:hover
  129. {
  130. background-color : #CC3300;
  131. }
  132. .style1
  133. {
  134. width: 20px;
  135. }
  136. .style3
  137. {
  138. width: 4px;
  139. }
  140. .style4
  141. {
  142. width: 5px;
  143. color: Red;
  144. }
  145. .style5
  146. {
  147. width: 525px;
  148. }
  149. .style6
  150. {
  151. height: 34px;
  152. }
  153. .style7
  154. {
  155. width: 525px;
  156. height: 34px;
  157. }
  158. .style8
  159. {
  160. height: 23px;
  161. }
  162. .style9
  163. {
  164. width: 136px;
  165. }
  166. .style10
  167. {
  168. height: 34px;
  169. width: 136px;
  170. }
  171. .style12
  172. {
  173. height: 34px;
  174. width: 20px;
  175. }
  176. .style14
  177. {
  178. height: 34px;
  179. width: 4px;
  180. }
  181. .style15
  182. {
  183. width: 120px;
  184. }
  185. </style>
  186. <div class="Heading">
  187. ModalPouUp Control</div>
  188. <div class="ContentInside">
  189. <asp:ScriptManagerProxy ID="ScriptManagerProxy1" runat="server">
  190. </asp:ScriptManagerProxy>
  191. </div>
  192. <div class="ContentInside">
  193. <asp:UpdatePanel ID="UpdatePanel3" runat="server" UpdateMode="Conditional">
  194. <ContentTemplate>
  195. <table style="width:100%;">
  196. <tr>
  197. <td class="style1">
  198. </td>
  199. <td class="style9">
  200. </td>
  201. <td class="style3">
  202. </td>
  203. <td class="style5">
  204. </td>
  205. <td>
  206. </td>
  207. </tr>
  208. <tr>
  209. <td class="style12">
  210. </td>
  211. <td class="style10">
  212. Insert New Data</td>
  213. <td class="style14">
  214. :</td>
  215. <td class="style7">
  216. <asp:LinkButton ID="LinkButton1" runat="server">Procede</asp:LinkButton>
  217. </td>
  218. <td class="style6">
  219. </td>
  220. </tr>
  221. <tr>
  222. <td class="style1">
  223. </td>
  224. <td class="style9">
  225. </td>
  226. <td class="style3">
  227. </td>
  228. <td class="style5">
  229. </td>
  230. <td>
  231. </td>
  232. </tr>
  233. </table>
  234. <asp:ModalPopupExtender ID="ModalPopupExtender1" runat="server"
  235. CancelControlID="btnClose" PopupControlID="ModalBox"
  236. TargetControlID="LinkButton1" BackgroundCssClass="modalBackground"
  237. DropShadow="True">
  238. </asp:ModalPopupExtender>
  239. </ContentTemplate>
  240. </asp:UpdatePanel>
  241. </div>
  242. <div class="ContentInside" id="ModalBox" runat="server"
  243. style="background-color: #0099CC; color: #FFFFFF; font-weight: bold; font-family: Cambria; font-style: normal; text-transform: capitalize">
  244. <asp:UpdatePanel ID="UpdatePanel1" runat="server">
  245. <ContentTemplate>
  246. <table style="width:100%;">
  247. <tr>
  248. <td class="style1">
  249. </td>
  250. <td class="style15">
  251. </td>
  252. <td class="style3">
  253. </td>
  254. <td class="style4">
  255. </td>
  256. <td>
  257. </td>
  258. <td>
  259. </td>
  260. </tr>
  261. <tr>
  262. <td class="style1">
  263. </td>
  264. <td class="style15">
  265. </td>
  266. <td class="style3">
  267. </td>
  268. <td class="style4">
  269. </td>
  270. <td>
  271. </td>
  272. <td>
  273. </td>
  274. </tr>
  275. <tr>
  276. <td class="style1">
  277. </td>
  278. <td class="style15">
  279. User name</td>
  280. <td class="style3">
  281. :</td>
  282. <td class="style4">
  283. *</td>
  284. <td>
  285. <asp:TextBox ID="txtUserName" runat="server" CssClass="TextBoxSize"></asp:TextBox>
  286. </td>
  287. <td>
  288. </td>
  289. </tr>
  290. <tr>
  291. <td class="style1">
  292. </td>
  293. <td class="style15">
  294. </td>
  295. <td class="style3">
  296. </td>
  297. <td class="style4">
  298. </td>
  299. <td>
  300. <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
  301. ControlToValidate="txtUserName" ErrorMessage="* Enter UserName" ForeColor="Red"
  302. ValidationGroup="abc"></asp:RequiredFieldValidator>
  303. </td>
  304. <td>
  305. </td>
  306. </tr>
  307. <tr>
  308. <td class="style1">
  309. </td>
  310. <td class="style15">
  311. Mobile Number</td>
  312. <td class="style3">
  313. :</td>
  314. <td class="style4">
  315. *</td>
  316. <td>
  317. <asp:TextBox ID="txtMobile" runat="server" CssClass="TextBoxSize"></asp:TextBox>
  318. </td>
  319. <td>
  320. </td>
  321. </tr>
  322. <tr>
  323. <td class="style1">
  324. </td>
  325. <td class="style15">
  326. </td>
  327. <td class="style3">
  328. </td>
  329. <td class="style4">
  330. </td>
  331. <td>
  332. <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
  333. ControlToValidate="txtMobile" ErrorMessage="* Enter Mobile No" ForeColor="Red"
  334. ValidationGroup="abc"></asp:RequiredFieldValidator>
  335. <asp:RangeValidator ID="RangeValidator1" runat="server"
  336. ControlToValidate="txtMobile" ErrorMessage="* Minimum 10 Digit Mobile Number"
  337. ForeColor="Red" MaximumValue="9999999999" MinimumValue="1000000000"
  338. Type="Double" ValidationGroup="abc"></asp:RangeValidator>
  339. </td>
  340. <td>
  341. </td>
  342. </tr>
  343. <tr>
  344. <td class="style1">
  345. </td>
  346. <td class="style15">
  347. </td>
  348. <td class="style3">
  349. </td>
  350. <td class="style4">
  351. </td>
  352. <td>
  353. <asp:Button ID="btnSave" runat="server" CssClass="ClickButton" Text="Save"
  354. onclick="btnSave_Click" ValidationGroup="abc" />
  355. <asp:Button ID="btnReset" runat="server" CssClass="ClickButton"
  356. onclick="btnReset_Click" Text="Reset" />
  357. <asp:Button ID="btnClose" runat="server" CssClass="ClickButton" Text="Close" />
  358. </td>
  359. <td>
  360. </td>
  361. </tr>
  362. <tr>
  363. <td class="style1">
  364. </td>
  365. <td class="style15">
  366. </td>
  367. <td class="style3">
  368. </td>
  369. <td class="style4">
  370. </td>
  371. <td>
  372. <asp:Label ID="lblMessage1" runat="server" ForeColor="Red"></asp:Label>
  373. </td>
  374. <td>
  375. </td>
  376. </tr>
  377. <tr>
  378. <td class="style1">
  379. </td>
  380. <td class="style15">
  381. </td>
  382. <td class="style3">
  383. </td>
  384. <td class="style4">
  385. </td>
  386. <td>
  387. </td>
  388. <td>
  389. </td>
  390. </tr>
  391. </table>
  392. </ContentTemplate>
  393. </asp:UpdatePanel>
  394. </div>
  395. <div class="ContentInside">
  396. <asp:UpdatePanel ID="UpdatePanel2" runat="server">
  397. <ContentTemplate>
  398. <table style="width:100%;">
  399. <tr>
  400. <td class="style8">
  401. </td>
  402. <td class="style8">
  403. <asp:GridView ID="GridView1" runat="server" BackColor="White"
  404. BorderColor="#CC9966" BorderStyle="None" BorderWidth="1px" CellPadding="4"
  405. AllowPaging="True" onpageindexchanging="GridView1_PageIndexChanging"
  406. PageSize="5">
  407. <FooterStyle BackColor="#FFFFCC" ForeColor="#330099" />
  408. <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="#FFFFCC" />
  409. <PagerStyle BackColor="#FFFFCC" ForeColor="#330099" HorizontalAlign="Center" />
  410. <RowStyle BackColor="White" ForeColor="#330099" />
  411. <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="#663399" />
  412. <SortedAscendingCellStyle BackColor="#FEFCEB" />
  413. <SortedAscendingHeaderStyle BackColor="#AF0101" />
  414. <SortedDescendingCellStyle BackColor="#F6F0C0" />
  415. <SortedDescendingHeaderStyle BackColor="#7E0000" />
  416. </asp:GridView>
  417. </td>
  418. <td class="style8">
  419. </td>
  420. </tr>
  421. <tr>
  422. <td>
  423. </td>
  424. <td>
  425. <asp:Label ID="lblMessage2" runat="server" ForeColor="Red"></asp:Label>
  426. </td>
  427. <td>
  428. </td>
  429. </tr>
  430. </table>
  431. </ContentTemplate>
  432. </asp:UpdatePanel>
  433. </div>
I will use LINQ to do the database operations.

add table

Complete C# Code
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7. using System.Drawing;
  8. public partial class Ajax_User_Controls_Modal_Pooup_Control : System.Web.UI.UserControl
  9. {
  10. protected void Page_Load(object sender, EventArgs e)
  11. {
  12. LoadGridData();
  13. }
  14. private void LoadGridData()
  15. {
  16. try
  17. {
  18. using (DataClassesDataContext DbContext = new DataClassesDataContext())
  19. {
  20. var Data = DbContext.tbl_ModalPopUp_Samples;
  21. //
  22. GridView1.DataSource = Data;
  23. GridView1.DataBind();
  24. }
  25. }
  26. catch (Exception Exc)
  27. {
  28. lblMessage2.Visible = true;
  29. lblMessage2.ForeColor = Color.Red;
  30. lblMessage2.Text = " Application Error : " + Exc.Message;
  31. }
  32. finally
  33. {
  34. //
  35. }
  36. }
  37. protected void btnSave_Click(object sender, EventArgs e)
  38. {
  39. DataSave();
  40. }
  41. private void DataSave()
  42. {
  43. try
  44. {
  45. using (DataClassesDataContext DbContext = new DataClassesDataContext())
  46. {
  47. tbl_ModalPopUp_Sample tbl = new tbl_ModalPopUp_Sample();
  48. tbl.UserName = txtUserName.Text;
  49. tbl.Mobile_No = Convert.ToInt64(txtMobile.Text);
  50. //
  51. DbContext.tbl_ModalPopUp_Samples.InsertOnSubmit(tbl);
  52. DbContext.SubmitChanges();
  53. }
  54. //
  55. lblMessage1.ForeColor = Color.Blue;
  56. lblMessage1.Text = "Data Saverd Successfully.";
  57. //
  58. ResetAll();
  59. LoadGridData();
  60. }
  61. catch (Exception Exc)
  62. {
  63. lblMessage1.Visible = true;
  64. lblMessage1.ForeColor = Color.Red;
  65. lblMessage1.Text = " Application Error : " + Exc.Message;
  66. }
  67. finally
  68. {
  69. //
  70. }
  71. }
  72. protected void btnReset_Click(object sender, EventArgs e)
  73. {
  74. ResetAll();
  75. lblMessage1.Text = "";
  76. lblMessage2.Text = "";
  77. }
  78. private void ResetAll()
  79. {
  80. txtUserName.Text = "";
  81. txtMobile.Text = "";
  82. }
  83. protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
  84. {
  85. GridView1.PageIndex = e.NewPageIndex;
  86. LoadGridData();
  87. }
  88. }
Run the application.
Run The Application

save data

Watch the GridView after saving the data.

gridview