
search
Saturday, December 13, 2008
Web.config Changes after installing membership tables

Tuesday, October 21, 2008
Creating Membership Tables
When the website is live and we want to use aspnetdb.mdf, we need to have an extra database webserver. Because of this reason we would like to have same database for tables and procedures of memebership and any other purpose that your site requires.
We have a possibility to have membership tables in a single database with the command aspnet_regsql.exe.
We need to follow the below steps to install membership tables in your database with the command aspnet_regsql.exe.
Goto to the Visual Studio 2005 command Prompt.

MicrosoftSoft Visual Studio 2005->
Visual Studio Tools ->
Visual Studio 2005 Command prompt
Below is the command prompt window that gets opened and run the command aspnet_regsql.exe


Soon after you run the command, you will find the 'Welcome to the ASP.NET SQL server setup Wizard ' window opened.
Click next.
After clicking next 'Select a Setup Option' window gets opened.

Select the default or the other option depending upon the requirement.
Click next and note the 'Select the Server and Database' window gets opened.
S
elect the database and click next.
Note 'confirm your settings' window gets opened.
Confirm your settings and click next otherwise, go to previous window and change the settings.

Click next and note 'The database has been created or modified' window has been opened.
Check the required tables are populated in the specified database.
Wednesday, April 9, 2008
How to disable right click
document.oncontextmenu=new Function("return false;")
Tuesday, March 11, 2008
Access Specifiers in .net
PUBLIC
As the name specifies, it can be accessed from anywhere. If a member of a class is defined as public then it can be accessed anywhere in the class as well as outside the class. This means that objects can access and modify public fields, properties, methods.
PRIVATE
As the name suggests, it can't be accessed outside the class. Its the private property of the class and can be accessed only by the members of the class.
INTERNAL
Friend & Internal mean the same. Internal is used in C#. Friends can be accessed by all classes within an assembly but not from outside the assembly.
PROTECTED
Protected variables can be used within the class as well as the classes that inherites this class.
PROTECTED INTERNAL
The Protected Internal can be accessed by Members of the Assembly or the inheriting class, and ofcourse, within the class itself.
Execution process in .net
Instead of being compiled into an executable containing native code, .NET application code is compiled into Microsoft intermediate language (MSIL) and stored in a file called an assembly.
At run time, the assembly is compiled to its final state by the CLR.
While running, the CLR provides memory management, type-safety checks, and other run-time tasks for the application.
Applications that run under the CLR are called managed code because the CLR takes care of many of the tasks that would have formerly been handled in the application’s executable itself.
Types of Applications in .net
Web applications
These applications provide content from a server to client machines over the Internet. Users view the Web application through a Web browser.
Web services
These components provide processing services from a server to other applications over the Internet.
Internet-enabled applications
These are stand-alone applications that incorporate aspects of the Internet to provide online registration, Help, updates, or other services to the user over the Internet.
Peer-to-peer applications
These are stand-alone applications that use the Internet to communicate with other users running their own instances of the application.
Tuesday, February 5, 2008
How to change Default DataBase in SQL Server 2005
Example:-
alter login sa with default_database = ourspace
How to Alter a column DataType in SQL Server 2005
ALTER TABLE [Table_Name]
ALTER COLUMN [ Field_Name] New_Datatype
Example :-
ALTER TABLE myTable
ALTER COLUMN fieldname nvarchar(255)
Adding a column to a existing Table in SQL Server 2005
ALTER TABLE [Table_Name]
ADD [Column_Name] Datatype null
Example:-
USE ourspace
ALTER TABLE items ADD Brand varchar(100) null
Friday, February 1, 2008
How to disable Back button of Internet Explorer
There is no direct way to disable the back button so that it is greyed-out and user cannot click on it.
However, there are some tricks using javascript which might be able to give you the results that we need, using javascripts window.history function with a session variable and automatically logging off and redirecting to the required page if user hits the back button.
javascript code
window.history.forward(1);
Thursday, January 31, 2008
Difference between ReadOnly and Constants
-> A constant is initialized at the time of its creation i.e Compile Time.
-> A ReadOnly can be assigned once in the class constructor allowing you to pass the value at Runtime.
Advantages of declaring Constant
->Declaring fields as constants protects from changing the value accidentally.
->Using constants we perform some optimization by not declaring any stack space for that field.
Tuesday, January 8, 2008
Validating EMail Id - Java Script Code
Validating EMail ID
Some times we want users to enter their EMail Id and we require it to validate.
The following code in java script will help you out.
Add a TextBox to enter email id and a Button (which has to be clicked by the user after entering email address) in .aspx page.
In the given example txtEmail is the id of the text box and btnEmailCheckOut is the id of Button.
In the Code behind .aspx.cs page add the below code in Page_Load event-
btnEmailCheckOut.Attributes.Add("onclick", "javascript:return CheckEmail('" + txtEmail.ClientID + "');");
The above code adds attribute to the button so as to execute a javascript function when the button is clicked. JavaScript function CheckEmail takes a parameter txtEmail.ClientID(id of TextBox which will hold Email Id).
Here's the java script function starts
function CheckEmail(ControlID)
{
var str=document.getElementById(ControlID).value;
if (str != "" )
{
var at="@"
var dot="."
var lat=str.indexOf(at)
var lstr=str.length
var ldot=str.indexOf(dot)
if (str.indexOf(at)==-1)
{
alert("Invalid E-mail ID");
document.getElementById(ControlID).focus();
return false;
}
if (str.indexOf(at)==-1 str.indexOf(at)==0 str.indexOf(at)==lstr)
{
alert("Invalid E-mail ID");
document.getElementById(ControlID).focus();
return false;
}
if (str.indexOf(dot)==-1 str.indexOf(dot)==0 str.indexOf(dot)==lstr str.lastIndexOf(dot)==lstr)
{
alert("Invalid E-mail ID");
document.getElementById(ControlID).focus();
return false;
}
if (str.indexOf(at,(lat+1))!=-1)
{
alert("Invalid E-mail ID");
document.getElementById(ControlID).focus();
return false;
}
if (str.substring(lat-1,lat)==dot str.substring(lat+1,lat+2)==dot)
{
alert("Invalid E-mail ID");
document.getElementById(ControlID).focus();
return false;
}
if (str.indexOf(dot,(lat+2))==-1)
{
alert("Invalid E-mail ID");
document.getElementById(ControlID).focus();
return false;
}
if (str.indexOf(" ")!=-1)
{
alert("Invalid E-mail ID");
document.getElementById(ControlID).focus();
return false;
}
return true;
}
}
Explanation
function CheckEmail(ControlID)
ControlID is the id of TextBox which will hold EMail ID.
var str=document.getElementById(ControlID).value;
document.getElementByID(ControlID) will Returns the reference to the element whose ID is specified.
document.getElementById(ControlID).value give us text entered in the textbox.
So, str will contain Email Id entered by the user in the text box.
if (str != "" )
checks whether str is null or not.
var lat=str.indexOf(at)
str.indexOf(at) gives first index(position) of at('@').
lat holds the index.
similarly,
var ldot=str.indexOf(dot)
ldot contains index of dat(' . ');
var lstr=str.length
str.length returns length of the str(EMail Id )
if (str.indexOf(at)==-1)
{
alert("Invalid E-mail ID");
document.getElementById(ControlID).focus();
return false;
}
Above fuctions checks whether '@' is present in EMail id or not if not it will show an alert message as shown below.
str.indexOf(at) checks for the first occurance of '@' if there is no occurance of '@' returns -1;
EMail Id should definitely contain @ otherwise it not valid.
document.getElementById(ControlID).focus();
focus() method will place cursor into the specified element .TextBox in the current context.
return false; Every function of javascript should return true or false.
If we wont mention return false; statement, function CheckEmail will be called repetedly and alert message will pop up as soon as we have closed early instance of alert message.
if (str.indexOf(at)==-1 str.indexOf(at)==0 str.indexOf(at)==lstr)
Above function will check whether there is any occurances of '@' or not and if ocuurance of '@' is equal to the length of the EMail ID i.e EMail ID ending with '@' which is absurd if, any of the condition is true then EMail Id is not valid.
if (str.indexOf(dot)==-1 str.indexOf(dot)==0 str.indexOf(dot)==lstr str.lastIndexOf(dot)==lstr)
Above function will check the ocurrances dot(' . ') is there or not and checks whether EMail Id is ending with dot or not.
if (str.indexOf(at,(lat+1))!=-1)
checks whether '@' occurs immediately after the first occurance of '@' .
sam@@yahoo.com is the invalid EMail Id.
if (str.substring(lat-1,lat)==dot str.substring(lat+1,lat+2)==dot)
The above statement checks whether the dot is followed immediately before or after at.
e.g. sam.@yahoo.com or sam@.yahoo.com
if (str.indexOf(" ")!=-1)
The above statement checks whether the statement contains any blank space or not.If you want some special character should not be there in your email id then use
if(str.indexOf("SPECIAL CHARACTER ")!=-1)
Query String
If we want to pass some values to another page it is possible through query string.
Query string is a string which is appended after the URL.
E.g. Response.Redirect( Sample.aspx?name=sam&age=21&sex=female);
In my previous post I have explained that Response.Redirect is used to move from one webpage to another webpage.
Sample.aspx is the destination page to which we want to migrate.
Query string is appended just after the URL, beginning with “?”
?name=sam&age=21&sex=female is the query string in the above example where Sample.aspx is the URL and name, age, sex are the parameters with their values sam, 21,female respectively .
Two parameters are separated by ‘&’ in the above example name and age are two different parameters and they are separated from ‘&’.
?name=sam&age=21
Value to the parameter is assigned after equal to (“=”).
?name=sam
Here name is parameter and sam is value assigned to the parameter.
Retrieving Query string in the Destination Page
Query string is retrieved by a command Request.QueryString(“parameter”) in asp.net
e.g. Request.QueryString["id"]
The first thing we do is to check if the query string exists in the first place before we start using it. It could look like this:
if (Request.QueryString["id"] != null)
{
// Do something with the querystring
}
The only problem with the above check to see if the query string is null, is that we don't take into consideration if the query string is filled or not.
That could lead to unhandled exceptions in the code. Instead we should check for query strings like this:
if (!String.IsNullOrEmpty(Request.QueryString["id"]))
{
// Do something with the querystring
}
So we do the check again more thoroughly:
if (!String.IsNullOrEmpty(Request.QueryString["id"]) && Request.QueryString["id"].Length == 5)
{
// Do something with the querystring
}
Now we know that we get a query string suitable for further processing.
You can then do more precise data type checks using the Parse or Convert method of most value types or by some other logic.

