public knowledge blog_load(sender Virendra)

                                                                                                                          Nothing shocks me, I am a Software Engineer.

Archive for July, 2009

Case Sensitive Comparison in SQL Server

Posted by Virendra Dugar on July 24, 2009

SQL Server performs the string comparison irrespective of the case. For eg. “VIRENDRA” and ‘virendra’ are equal when we do comparison in SQL Server.

I found an article which gives complete detail about case sensitive string comparison.

Below are the techniques to do case sensitive comparison

  • Converting data to binary type before comparison.
  • Using the COLLATE clause to dictate the case sensitiveness of the query.
  • Using BINARY_CHECKSUM function.
  • Changing the collation of the column permanently, so that all comparisons are case sensitive by default.
  • Using computed columns.

Check the original article for more details.



Posted in SQL Server | Tagged: | Leave a Comment »

JavaScript Best Pratices

Posted by Virendra Dugar on July 17, 2009

Check this article on Best Pratices of JavaScript.


Posted in JavaScript | Tagged: | Leave a Comment »

Access ViewState Across the Pages

Posted by Virendra Dugar on July 2, 2009

Before I start this article, Let me ask you something. Is it possible to access the ViewState variable of one page to another page? I don’t know what is your answer. Well, frankly speaking, My answer was  also “NO”  before writing this article As it is said that ViewState is page specific that means it is available on the same page only on which it is created. Once you redirect to another page, previous page viewstate is no more accessible. But that is not true.Yes, we can access the viewstate variables across the pages. This is only possible if Cross Page Posting or Server.transfer is used to redirect the user on other page. If Response.redirect is used then ViewState can not be accessed across the pages.

Before you go down, Please read these articles on Cross Page Posting and Server.transfer.

Ok, So all set now.. I will demonstrate this using the demo created by me. You can download the demo from here.

I have created two .aspx page named
1. ViewStateContainer.aspx : This page set the ViewState variable and transfers the user to another page using Server.transfer.
2. AccessViewState.aspx : This page access the ViewState variable of ViewStateContainer.aspx Page.

This is the code of ViewStateContainer.aspx Page :

ViewState Container Page

As you can see, I have set a ViewState variable in Page Load and transfers the user to AccessViewState.aspx page using Server.transfer() method.
This page also contains a method ReturnViewState() which actually returns the ViewState of this page to the calling function. Return type of the method is StateBag Class.

StateBag Class : This class is the primary storage mechanism for all HTML and Web server controls. It stores attribute/value pairs as strings associated with the control. It tracks changes to these attributes only after the OnInit method is executed for a page request, and saves the changes to the page’s or control’s view state.

Now let’s take look at AccessViewState.aspx Page code:

Access View State

Whenever we use Server.transfer or Cross Page Posting, We can get the previous page object via PreviousPage Property. Using Previous Page, we can find the controls of previous page. As for example, One can access Label control placed in ViewStateContainer Page in Current Page.

Looking at the code, I have created a PreviousPageViewState property in this page, which returns the previous page’s ViewState. It first checks whether PreviousPage is null or not, if it’s not null then create an object of the previous page. Now using Reflection, we can invoke the method of the previous class. Using MethodInfo class, I have invoked the ReturnViewState() method of ViewStateContainer Page.

In Page_Load event, I am able to access the ViewState variable of  ViewStateContainer Page. You can access all the viewstate variables set in ViewStateContainer Page.


Posted in ASP.NET | Tagged: | Leave a Comment »

%d bloggers like this: