Thursday, 16 March 2017


AJAX ModalPopupExtender Show/Hide (Open/Close) Using JavaScript in ASP.Net


 Ajax ModalPopup is very similar to JavaScript Alert boxes,But They can be customize as based on our need.Ajax ModalPopupExtender is Very easy to implement we just have to only two properties which is TargetControlID and CancelControlID(for closing modal).


Ex: TargetControlID="btnShowPopup" CancelControlID="btnNo"



Here whenever we click on btnShowPopup button control modalpopupextender will show popup and when we click on btnNo button it will close the popup. Now I want to open popup and close popup whenever click on other button controls also in that case what we can do? By using JavaScript $find() function we can show or hide modalpopupextender easily. 



JavaScript Functions will be like this




<script language="javascript" type="text/javascript">

//Function to Hide ModalPopUp

function Hidepopup() {

$find('ModalPopupExtender1').hide();

}
//Function to Show ModalPopUp
function Showpopup() {
$find('ModalPopupExtender1').show();
}
</script>


 Aspx page is:

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Untitled Page</title>
<script language="javascript" type="text/javascript">
//Function to Hide ModalPopUp
function Hidepopup() {
$find('ModalPopupExtender1').hide();
}
//Function to Show ModalPopUp
function Showpopup() {
$find('ModalPopupExtender1').show();
}
</script>
</head>
<body>
<form id="form1" runat="server">
<ajax:ToolkitScriptManager ID="ScriptManager1" runat="server">
</ajax:ToolkitScriptManager>
<asp:Button ID="btnShowPopup" runat="server" style="display:none" />
<ajax:ModalPopupExtender ID="ModalPopupExtender1" runat="server"TargetControlID="btnShowPopup" PopupControlID="pnlpopup"
CancelControlID="btnNo" BackgroundCssClass="modalBackground">
</ajax:ModalPopupExtender>
<asp:Panel ID="pnlpopup" runat="server" BackColor="White" Height="100px" Width="400px"style="display:none">
<div>
Confirm Box
<a href = "javascript:void(0)" onclick = "closepopup()">Hide PopUp</a>
<a href = "javascript:void(0)" onclick = "Showpopup()">Show PopUp</a>
<asp:ImageButton ID="btnYes" OnClick="btnYes_Click" runat="server"ImageUrl="~/Images/btnyes.jpg"/>
<asp:ImageButton ID="btnNo" runat="server" ImageUrl="~/Images/btnNo.jpg" />
</div>
</asp:Panel>
</form>
</body>
</html> 

Tuesday, 14 March 2017



Retrieve Session Value in ASP.NET using C# with Example



Hi,I am Navid Shaikh today i am going to show you how to send (pass) Value one page to another page using Session   in Asp.net C#


The session state is used to maintain the session of each user throughout the application. Session allows information to be stored in one page and access in another page and support any type of object. In many websites we will see the functionality like once if we login into website they will show username in all the pages for that they will store username in session and they will access that session username in all the pages.

Whenever user enters into website new session id will generate for that user. This session Id will delete when he leave from that application. If he enters again he will get new session Id.


We can check this one with simple example for that create one new website and open Default.aspxpage and write the following  code



<html xmlns="http://www.w3.org/1999/xhtml">

<head id="Head1" runat="server">

<title>Asp.net Session State Example in C#</title>

</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr>
<td>UserName:</td><td><asp:TextBox ID="txtUname" runat="server"/></td>
</tr>
<tr>
<td>Password:</td><td><asp:TextBox ID="txtPass" runat="server"/></td>
</tr>
<tr><td></td><td> <asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click" /></td></tr>
</table>
</div>
</form>
</body>
</html>


After that write the following code in button click Event


protected void btnSubmit_Click(object sender, EventArgs e)
{
Session["Username"] = txtUname.Text;
Session["Password"] = txtPass.Text;
Response.Redirect("Default2.aspx");
}


Add second page in project and write following code


<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title> Second Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h3>Default2.aspx</h3>
<table>

<tr>
<td>Your Username: </td><td><b><asp:Label ID="lblUname" runat="server"/></b></td>
</tr>
<tr>
<td>Your Password</td><td><b><asp:Label ID="lblPass" runat="server"/></b></td>
</tr>
<tr><td></td><td> </td></tr>
</table>
</div>
</form>
</body>
</html>

After that write the following code in Page Load Event

protected void Page_Load(object sender, EventArgs e)
{
     if(!IsPostBack)
     {
          lblUname.Text = Session["Username"].ToString();
          lblPass.Text = Session["Password"].ToString();
      }
}