Good CSS URL for Asp.net Project


Hi

Here is some nice css url, from where you can take the css code and use it in your project

10 CSS example

Some useful CSS example

25 CSS Example

31 CSS Example

Posted in CSS. 1 Comment »

How to do form authentication using sql server as database in asp.net ?



Hi

Since you are knowing that form authentication is more secure as compare to other authentication in asp.net. You can read more on “Authentication and authorization” from this excellent artical.
Authentication and authorization

We can do form authentication using sql server as database in asp.net as given bellow steps

Step1: Take a “Login” Control from asp.net Toolbox and kept on “Login.aspx” page.

Step2: Create “Home.aspx” page which will display after proper authentication.

Step3: Now click on “Login1_Authenticate” event of “Login” control of Login.aspx page and write the code like this

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Web.Security;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
    {
        using (SqlConnection con = new SqlConnection(" Here will be your connection string"))
        {
            using (SqlCommand cmd = new SqlCommand("Select UserName,Password from tblLogin where UserName=@UserName and Password=@Password", con))
            {
                cmd.Parameters.AddWithValue("@UserName", Login1.UserName);
                cmd.Parameters.AddWithValue("@Password", Login1.Password);
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                DataTable dt = new DataTable();
                da.Fill(dt);
                if (dt.Rows.Count > 0)
                {
                    //This code is generating the Cookies 
                    FormsAuthentication.RedirectFromLoginPage(Login1.UserName, Login1.RememberMeSet);

                }
            }
        }
    }
}

Step4: Now go to webconfig file and make the configuration like this

 <authentication mode="Forms">
      <forms defaultUrl="Home.aspx" loginUrl="~/Login.aspx"
      slidingExpiration="true" timeout="20">
      </forms>
    </authentication>
    <authorization>
      <deny users="?"/>
    </authorization>

If authentication will be sucessful then it will display “Home.aspx”.

Coding standard for vb.net and C#


Hi
Just before few months i was working for one big MNC client. There we were implementing some coding standard for vb.net and C# project. I have summarized that coding standard like this

Coding standard for vb.net

1. Declaration of variable should be in Camel case

2. Private Name should be in Camel case

3. Public and Properties should be in Pascal case

4. All Constant should be in Caps or Upper Case

5. “_” should not be used

6. Object should not be used

7. Short should not used

8. CShort should not be used

9. Method name should be in Pascal case

10. Parameter variable should be in Camel case

11. Exit sub and exit should be removed

12. Call keyword should be removed

13. Function Name should not be used as return variable

14. I,k,j should not be used. We should have to used proper naming

15. “ ” should be replaced with string.empty

16. Option strict and Option Explicit should be ON

17. Index1 should be “indexOne”

18. Function name should not be with “fun” prefix. It should be in pascal

19. Subroutine name should not be with “sub” prefix and it should be in pascal

20. “On Error Resume Next” statement is there then no need to use try catch block.

Coding Standard for C#

1. Declaration of variable should be in Camel case
string empName=string.Empty;

2. Class Name should be in Pascal

public class HelloWorld()
{
}

3. Method name should be Pascal

public string SayHello( String name )
{
return name;
}

4. All Constant should be in Caps or Upper Case

5. “_” should not be used while giving parameter and variable Name

string emp_Name;

It should be like this
string empName;

6. Parameter variable should be in Camel case

public string SayHello( String name )
{
return name;
}

7. “ ” should be replace by string.empty

8. I,j,k Naming should not be used.

9. Comment should not be written in every line of code. We should have to write proper method name to make more readable code and give the comment where logic is some complex.

10. use C# specified Type rather than alias type defined in the System namespace.

Good

int age;
string name;

Not Good

Int16 age;
String name;

11. Try to minimize the exception in code. Use specific exception handling for particular type of error

12 . Try to use list instead of “Array” or “Arraylist”.

13. use using keyword to dispose idisposable object while working with “Sqlconnection”,sqlcommand etc.

14. Use proper exception handling code while writing the code .

15. If some method, we are using in one class only then we should not have to use Public access modifier.

Note: If you feel, this is not a proper or i m missing some important point then feel free to share your idea.

How to show alert message while closing the page in asp.net ?


Hi

In our asp.net project so many time we will get a senario to give confirmation alert message whenever somebody click on close icon of page specially in long registration page.

We can do this task using few line of javascript like this.

<script language="JavaScript" type="text/javascript">
window.onbeforeunload = Unload_Call;

function Unload_Call() {
var Message = "Are you sure,do you want to leave this page?";
return Message;
}
</script>

How to fire submit button on enter key press on page in asp.net ?


Hi

while working on asp.net project, so many time we will get a requirement to submit data on “Enter Key” press.

We can do this task like this
1.If we have to make “Enter Key” as default save button then we can do like this in .aspx page

<form id="form1" defaultbutton="BtnSubmit" runat="server">

//html code

</form>

2. If we have two or more section of registration form and if the user is on that section and if we have make there “Enter Key” as default save button then we can do like this in panel

<asp:Panel ID="Panel1" DefaultButton="Button1" runat="server">

//html code

</Panel>