data source does not support server-side data paging uisng asp.net Csharp

30. April 2010

Yesterday some one mail me and ask about data source does not support server side data paging.So i write the the solution here please if you have got this problem read this article and see the example code this will help you a Lot.The only change you have to do is in the DataBind().
Here you have used the SqlDataReader to read data retrieved from the database, but SqlDataReader is forward only. You can not traverse back and forth on it.
So the solution for this is using DataAdapter and DataSet.
So your function may change some what like this

private void DataBind()
{
//for grid view
SqlCommand cmdO;
string SQL = "select * from TABLE ";
conn.Open();
cmdO = new SqlCommand(SQL, conn);
SqlDataAdapter da = new SqlDataAdapter(cmdO);
DataSet ds = new DataSet();
da.Fill(ds);
GridView1.Visible = true;
GridView1.DataSource = ds;
GridView1.DataBind();
ds.Dispose();
da.Dispose();
conn.Close();

}



This surely works. The reset of your code is fine. Enjoy coding.


 


Author: Aamir Hasan     औथोर: आमिर हसन       أثر أمير حسن .

ALL, asp.net , ,

View State Management in ASP.NET 4.0

28. April 2010

In ASP.NET 4.0 we have more control over maintaining view state for page let’s see how we can manage View State more efficiently in asp.net 4.0. In the earlier version of asp.net we have View State optional that means we can turn View State view EnableViewState property.

ASP.NET 4.0 things are different with respect to above scenario. Now we have one more property called ViewStateMode Property. This property help us greatly in managing View State. It has there values Enabled,Disabled,Inherit. With this property you can enable View State of control even if View State is disabled. So now we will have facility to turn off the View State of parent controls like page and then we can decide which control will have View State enabled.

In ASP.NET 4.0 ViewStateMode property will accept following values.

  • Enabled- This will enable View State for particular control and also for any child control which have ‘Inherit’ value for this property or nothing set for this property.
  • Disabled- This will disable View State for that particular control.
  • Inherit- This will specify that control will use the parent control ViewStateMode property.

Hope this will help you understanding View State Management in ASP.NET 4.0.



Author: Aamir Hasan     औथोर: आमिर हसन       أثر أمير حسن .

ALL, asp.net 4.0 ,

Process for Securing Web Sites and Applications

28. April 2010

The following quick-start guide provides a detailed overview of how to configure security for IIS 6.0.


Reduce the Attack Surface of the Web Server


1.       Enable only essential Windows Server 2003 components and services.

2.       Enable only essential IIS 6.0 components and services.

3.       Enable only essential Web service extensions.

4.       Enable only essential Multipurpose Internet Mail Extensions (MIME) types.

5.       Configure Windows Server 2003 security settings.


Prevent Unauthorized Access to Web Sites and Applications

1.       Store content on a dedicated disk volume.

2.       Set IIS Web site permissions.

3.       Set IP address and domain name restrictions.

4.       Set the NTFS file system permissions.


Isolate Web Sites and Applications

1.       Evaluate the effects of impersonation on application compatibility:

2·         Identify the impersonation behavior for ASP applications.

3·         Select the impersonation behavior for ASP.NET applications.

4.       Configure Web sites and applications for isolation.


Configure User Authentication

1.       Configure Web site authentication.

2·         Select the Web site authentication method.

3·         Configure the Web site authentication method.

4.       Configure File Transfer Protocol (FTP) site authentication.


Encrypt Confidential Data Exchanged with Clients

1.       Use Secure Sockets Layer (SSL) to encrypt confidential data.

2.       Use Internet Protocol security (IPSec) or virtual private network (VPN) with remote administration.


Maintain Web Site and Application Security

1.       Obtain and apply current security patches.

2.       Enable Windows Server 2003 security logs.

3.       Enable file access auditing for Web site content.

4.       Configure IIS logs.

5.       Review security policies, processes, and procedures.

 Note:To secure the Web sites and applications in a Web farm, use the process described in this chapter to configure security for each server in the Web farm.

Reducing the Attack Surface of the Web Server

Immediately after installing Windows Server 2003 and IIS 6.0 with the default settings, the Web server is configured to serve only static content. If your Web sites consist of static content and you do not need any of the other IIS components, then the default configuration of IIS minimizes the attack surface of the server. When your Web sites and applications contain dynamic content, or you require one or more of the additional IIS components, you will need to enable additional features. However, you still want to ensure that you minimize the attack surface of the Web server. The attack surface of the Web server is the extent to which the server is exposed to a potential attacker.


Preventing Unauthorized Access to Web Sites and Applications


Each Web site and application in IIS 6.0 and Windows Server 2003 is stored as a grouping of folders and files. Unauthorized access to, or modification of, these files and folders can present a serious breach of security. You must ensure that only authorized users can access or modify the Web sites and applications that are hosted on your Web server.



Author: Aamir Hasan     औथोर: आमिर हसन       أثر أمير حسن .

ALL, IIS 6 ,

Regular Expression- How To Replace Non-Numeric characters In a String

19. April 2010

An easy way to remove all non-alphanumeric characters from a string and it took some time to find the easiest way was to use RegEx.Replace().
There are exceptions to this rule; some characters are special, and don't match themselves. Instead, they signal that some out-of-the-ordinary thing should be matched, or they affect other portions of the RE by repeating them. Much of this document is devoted to discussing various metacharacters and what they do.

Here's a complete list of the metacharacters; their meanings will be discussed in the rest of this HOWTO.

. ^ $ * + ? { [ ] \ | ( )


First import the namespace System.Text.RegularExpressions;

Then here's how to do so:

C#

 

   // Replace non-numeric characters

    string str = "12d223*23#22";

   string newStr = Regex.Replace(str, @"[^\d]", "");

    // Displays 122232322


VB.NET

 

   ' Replace non-numeric characters

    Dim str As String = "12d223*23#22"

    Dim newStr As String = Regex.Replace(Str, "[^\d]", "")

    ' Displays 122232322

Author: Aamir Hasan     औथोर: आमिर हसन       أثر أمير حسن .

ALL, asp.net ,

How to combine c# and html/javaScript

17. April 2010

Yesterday some call me and ask me about how to conbine c# and HTML/javascript so i decided to write a simple example which will helps to others. You can use variable and function of codebehind in aspx but it must be protected or public.

Note:If the variable or function is private in codebehind. It will give this you error.variable' is inaccessible due to its protection level.

Becareful in using <%= %> inline syntax....it will be only working for clientside elements. If you want to use the same methodology for ServerSide controls (means setting some attributes and properties), then you got to use <%# %> with Page.DataBind() on the page_load...then there will not be any problem....

And also there is one more Syntax - <%$ %> - it is the expression syntax....whatever expression entered here will be evaluated at runtime...

.cs code

public partial class Default2 : System.Web.UI.Page
{
    protected int variable = 40;
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected int DoubleIt(int _varialbe)
    {
        return _varialbe * 2;
    }
}


.aspx code
--------------

 <script type="text/javascript">

 

function myFunction()
        {
            alert('<%=variable %>');
            alert('<%=DoubleIt(50) %>');
        }


        </script>

 

 


Author: Aamir Hasan     औथोर: आमिर हसन       أثر أمير حسن .

ALL, asp.net, Javascript ,



User Name: Guest

Your Ip: 38.107.191.91
Time: