4
Posted on 11:17 PM by prajeesh and filed under , ,
These three methods are used to clear session variables from the server,but the difference is
Session.Abandon includes Session.RemoveAll and also deletes the session id created for the session. So, subsequent request to .aspx page would create a new session with a new session id. Session.RemoveAll will remove all the user defined session variables but still keeps the session active.so if u want to end session you must use Session.Abandon().
Session.Clear() do the same job as Session.RemoveAll(). Shout it kick it on DotNetKicks.com
4
Posted on 9:34 AM by prajeesh and filed under , ,

In some websites we can see buttons like A A A to increse font size of your website for giving readability to disabled people also,we can do it many ways,one option is to dynamically change css or using javascript.here is a simple method using javascript to do this.


Step 1: Add the following Javascript in the insde the <HEAD> tag of your HTML.


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


function changeFontSize(inc)


{


var p = document.getElementsByTagName('p');


for(n=0; n<p.length; n++) {


if(p[n].style.fontSize) {


var size = parseInt(p[n].style.fontSize.replace("px", ""));


} else {


var size = 12;


}


p[n].style.fontSize = size+inc + 'px';


}


}


</script>



Step 2: Insert the following HTML anywhere in your blog - you can customize the text or replace it with visual graphics (like the alphabet A - one small and the other one slightly large)

<a href="javascript:changeFontSize(1)">Increase Font Size</a>
<a href="javascript:changeFontSize(-1)">Decrease Font Size</a>

You can extend this to either all the HTML elements on your blog or limit it to only the text sections. The font size is specified in pixels.



Shout it kick it on DotNetKicks.com
0
Posted on 6:21 AM by prajeesh and filed under ,
what is a GUID? “GUID is a Globally Unique Identifier or GUID is a special type of identifier used in software applications in order to provide a reference number which is unique in the context for which it is used, for example, in defining the internal reference for a type of access point in a software application, or for creating unique keys in a database. While each generated GUID is not guaranteed to be unique, the total number of unique keys is so large that the probability of the same number being generated twice is very small.” (Wikipedia)
  • GUID ensures global uniqueness

How to create GUID in c#.net:

Guid CartGUID = Guid.NewGuid();

GUID's are very helpful when we are implementing e-commerce websites,for giving shopping cart id's.

Shout it kick it on DotNetKicks.com
0
Posted on 6:33 AM by prajeesh and filed under , ,

Hello friends,Security is a major concern when we are developing web applications
Asp.net provides you three types of authentication providers,that are windows,passport and Formss based.

Windows:
This uses capabilities of ISS for authentication,and passes the identity to code,this is the default authentication provider for asp.net.
passport:
this is an authentication service provided by Microsoft that offers a single logon facility and membership services for your asp.net website.
Forms:
Forms authentication provides you with a way to handle authentication using your own custom logic with in an ASP.NET application.
When a user requests a page for the application that requires authentication,ASP.NET checks for the presence of a special session cookie.
If the cookie is present, ASP.NET assumes the user is authenticated and processes the requested page.
If the cookie isn't present, ASP.NET redirects the user to a page you have provided as login page

This post gives you a small idea on how to configure your asp.net application for forms based authentication:

First of all you need to create a login page with two text boxes and one login button:

Refer the code below:


<
asp:Panel ID="Panel1" runat="server" CssClass="login_box_big" Width="400px">
<table ><tr>
<td align="left" class="side_menu">&nbsp; Login</td>
</tr><tr><td align="left">
<b>UserName:</b><asp:TextBox ID="txtUserName" runat="server"></asp:TextBox>
</td></tr><tr><td align="left">
<b>Password:</b>&nbsp;<asp:TextBox ID="txtPassword" runat="server"
TextMode="Password"></asp:TextBox>&nbsp;</td></tr><tr><td>

<asp:Button ID="LoginBtn" runat="server" CssClass="button"

onclick="Button1_Click" Text="Login" /></td></tr><tr><td>

<asp:Literal ID="ltrerror" runat="server" EnableViewState="False" Text="&lt;div style=&quot;background-color:red;width:300px;color:white&quot; &gt;Error: Invalid Password&lt;/div&gt;&lt;div style=&quot;height:10px;&quot;&gt;

&lt;/div&gt;"

Visible="False"></asp:Literal></td></tr></table></asp:Panel>

In Login Buttons click event write the following code:

protected void LoginBtn_Click(object sender, EventArgs e)

{

if (txtUserName.Text=="YourUserName" && txtPassword.Text=="YourPassword")
{

FormsAuthentication.RedirectFromLoginPage(txtUserName.Text,false);

}

else

{

ltrerror.Visible = true;

}

}

If you want to authenticate all pages in a folder in your application

(for exaple :Admin),put a web.config file in your folder and put the following tags inside <configuration> and <configuration/>tags

<system.web>

<authorization>

<deny users="?" />

</authorization>

</system.web>

<system.web>

<authorization>

<allow users="*" />

</authorization>

</system.web>

In the web.config file in your root of the application put the following tags inside <system.web> and </system.web> tags

<authentication mode="Forms">

<forms name="AUTH" loginUrl="~/Login.aspx" protection="All" timeout="120" path="/">

</forms>

</authentication>

<authorization>

<allow users="*"/>

</authorization>

the timeout section controls the interval at which the authentication cookie is regenerated.

Happy coding



Shout it kick it on DotNetKicks.com
0
Posted on 2:06 AM by prajeesh and filed under , ,

Hi friends,

In some situations we need to export grid view content in our asp.net web page to excel sheet for future reference,or printing,here is the sample code to do that.all u have to do is place the following code into click event of export to excel button,and change grid view name and excel filename.

protected void BtnExport_Click1(object sender, ImageClickEventArgs e)

{

string attachment = "attachment; filename=Contacts.xls";

Response.ClearContent();

Response.AddHeader("content-disposition", attachment);

Response.ContentType = "application/ms-excel";

StringWriter sw = new StringWriter();

HtmlTextWriter htw = new HtmlTextWriter(sw);

GridView1.RenderControl(htw);

Response.Write(sw.ToString());

Response.End();

}

Shout it kick it on DotNetKicks.com
0
Posted on 11:07 PM by prajeesh and filed under , , ,
A.Using Real Player Activex Object

just place the following code to your asp.net page

<OBJECT ID=RVOCX CLASSID="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA"

WIDTH="180" HEIGHT="159">

<PARAM name="src" value="Media00.ram">

<PARAM name="autostart" value="false">

<PARAM name="controls" value="default">

<PARAM name="console" value="video">

</OBJECT>

or

<EMBED TYPE="audio/x-pn-realaudio-plugin" SRC="Media00.ram" WIDTH="180" HEIGHT="159" AUTOSTART="false" CONTROLS="all" CONSOLE="video"> </EMBED>

Note:You can embed a RealOne Player presentation in a Web page using <EMBED> tags, <OBJECT> tags, or both. When you use <EMBED>, your presentation will work in browsers that support the Netscape plug-in architecture,Even when you use the <EMBED> tag, RealOne Player communicates with Internet Explorer browsers using ActiveX technology. This makes the Netscape <EMBED> tag compatible with both major browsers, including Internet Explorer 6 and later.

Change “Media00.ram” to your media path.(Example : mysong.mp3)

Tips:

1.If you are giving a media path directly,the real player will only start playing after the entire media is downloaded. If you want to give a streaming like effect in your application(start playing with downloading),you open a notepad and insert media path in it such as http://yourpage/test.mp3 save this file with .ram extension and link this file from object/embed tags.

2.If you want to open real player in user computer from your web page ,just place a link

<a href="Media00.ram">Click here to play </a>

3.You can also controll embedded players playback options using javascript

<EMBED TYPE="audio/x-pn-realaudio-plugin" NAME=demo SRC="Media00.ram" WIDTH=100 HEIGHT=30

CONSOLE=one CONTROLS=Default BACKGROUNDCOLOR=white MAINTAINASPECT=true>

<INPUT TYPE="button"VALUE="Play"onClick="document.demo.DoPlay()">

<INPUT TYPE="button"VALUE="Pause"onClick="document.demo.DoPause()">

<INPUT TYPE="button"VALUE="Stop"onClick="document.demo.DoStop()">

4.for more information about real player embedding please refer the following guide

Real Networks Production Guide

B.Using Windows Media Player

<OBJECT ID='MediaPlayer1' name='MediaPlayer' CLASSID='CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6' height=100 width=400>

<PARAM name='URL' value='yourmusic.mp3'>

<PARAM name='AutoStart' value='True'>

<PARAM name='balance' value='0'>

<PARAM name='enabled' value='True'>

<PARAM name='fullScreen' value='False'>

<PARAM name='playCount' value='False'>

<PARAM name='volume' value='100'>

<PARAM name='rate' value='22'>

<PARAM name='StretchToFit' value='True'>

<PARAM name='enabledContextMenu' value='True'>

<PARAM name='uiMode' value='full'>

</OBJECT>

Tips:

1.If you are giving a media path directly,the media player will only start playing after the entire media is downloaded. If you want to give a streaming like effect in your application(start playing with downloading),you open a notepad and insert media path in it such as http://www.yourweb/music/test.mp3 save this file with .m3u extension and link this file from object/embed tags.




Shout it kick it on DotNetKicks.com
2
Posted on 10:19 PM by prajeesh and filed under , ,
Hi friends, here is a simplest way of javascript client side validation for an asp.net registration for ,all you need to do is place this code inside script tag and change thename of Controls to your control names.

function validateregform()

{

if (document.getElementById("<%
=txtName.ClientID%>").value=="")
{
alert("Name Field can not be blank");
document.getElementById("<%=txtName.ClientID%>").focus();
return false;
}

if(document.getElementById("<%=txtEmail.ClientID %>").value=="")
{
alert("Email id can not be blank"); document.getElementById("<%=txtEmail.ClientID%>").focus();
return false;
}
var emailPat = /^(\".*\"[A-Za-z]\w*)@(\[\d{1,3}(\.\d{1,3}){3}][A-Za-z]\w*(\.[A-Za-z]\w*)+)$/;
var emailid=document.getElementById("<%=txtEmail.ClientID%>").value;
var matchArray = emailid.match(emailPat);
if (matchArray == null)
{
alert("Your email address seems incorrect. Please try again.");
document.getElementById("<%=txtEmail.ClientID%>").focus();
return false;
}

if(document.getElementById("<%=txtWebURL.ClientID %>").value=="")
{
alert("Web URL can not be blank");
document.getElementById("<%=txtWebURL.ClientID%>").value="http://" document.getElementById("<%=txtWebURL.ClientID%>").focus(); return false;
}
var Url="^[A-Za-z]+://[A-Za-z0-9-_]+\\.[A-Za-z0-9-_%&\?\/.=]+$" ;
var tempURL=document.getElementById("<%=txtWebURL.ClientID%>").value;
var matchURL=tempURL.match(Url); if(matchURL==null)
{
alert("Web URL does not look valid");
document.getElementById("<%=txtWebURL.ClientID%>").focus();
return false;
}

if (document.getElementById("<%=txtZIP.ClientID%>").value=="")
{
alert("Zip Code is not valid");
document.getElementById("<%=txtZIP.ClientID%>").focus();
return false;
}
var digits="0123456789";
var temp;
for (var i=0;i<%=txtzip.clientid%>").value.length;i++)
{
temp=document.getElementById("<%=txtZIP.ClientID%>").value.substring(i,i+1);
if (digits.indexOf(temp)==-1) {
alert("Please enter correct zip code");
document.getElementById("<%=txtZIP.ClientID%>").focus(); return false;
}
} return true;
}

Here validateregform contains four functions to validate name,email,web url and zip code.

Shout it kick it on DotNetKicks.com