Padam's blog

I talk more about dot net and spend my most of the time with dot netting.
sys.webforms.PageRequestManagerParserErrorException

I have one dropdown in my page and my problem is sometimes when I select from the dropdown I get an error dialog box

"sys.webforms.PageRequestManagerParserErrorException: The message recieved from the server could not be parsed.

Common causes for this error are when the response is modified by the calls to Response.Write().response filters,HttpModules,

or server trace is enabled. Details:Error parsing near 'ession']|"\\d{0,9}"|<div style ='backgrou'." and nothing is displayed.

But when I refresh the page and do the same, it displays. So this error occurs sometimes all of a certain.

Can any one help me out!!!

Posted 04-13-2010 4:09 PM by Padam Raj Gurung | with no comments

lamda expression cool feature!!

like me, you may be one of the busy programmer..messing with long and time consuming queries..

then, try out lamda expression is very cool and superfast..

if you are in hard time, donot forget to use it..

u can also use linqpad like sql server management studio for it.

a simple example of lambda expression:

 

i want to select all the employee whose firstname starts with padam

 

db.Employee.where(x=>x.Firstname == 'padam')

have a great day!!

Posted 04-12-2010 5:19 PM by Padam Raj Gurung | with no comments

Filed under: ,

Dependency Injection

Normal 0 false false false EN-US X-NONE SA MicrosoftInternetExplorer4


 

Constructor Injection:

 

  interface IBusinessLogic

   {

     //Some code

   }

  

   class ProductBL : IBusinessLogic

   {

     //Some code

   }

  

   class CustomerBL : IBusinessLogic

   {

     //Some code

   }

   public class BusinessFacade

   {

      private IBusinessLogic businessLogic;

      public BusinessFacade(IBusinessLogic businessLogic)

      {

         this.businessLogic = businessLogic;

      }

   }

You'd instantiate the BusinessLogic classes (ProductBL or CustomerBL) as shown below:

   IBusinessLogic productBL = new ProductBL();

Then you can pass the appropriate type to the BusinessFacade class when you instantiate it:

   BusinessFacade businessFacade = new BusinessFacade(productBL);

 

 

Setter  Injection:

 

public class BusinessFacade

     {

      private IBusinessLogic businessLogic;

  

      public IBusinessLogic BusinessLogic

         {

          get

          {

            return businessLogic;

          }

  

            set

          {

            businessLogic = value;

          }

        }

     }

 

The following code snippet illustrates to implement setter injection using the BusinessFacade class shown above.

 

   IBusinessLogic productBL = new ProductBL();

   BusinessFacade businessFacade = new BusinessFacade();

   businessFacade.BusinessLogic = productBL;

 

 

Interface Injection:

 

    interface IBusinessLogic

   {

     //Some code

   }

  

   class ProductBL : IBusinessLogic

   {

     //Some code

   }

  

   class CustomerBL : IBusinessLogic

   {

     //Some code

   }

  

   class BusinessFacade : IBusinessFacade

   {

      private IBusinessLogic businessLogic;

      public void SetBLObject(IBusinessLogic businessLogic)

      {

         this.businessLogic = businessLogic;

      }

   }

 

In the code snippet above, the SetBLObject method of the BusinessFacade class accepts a parameter of type IBusinessLogic. The following code shows how you'd call the SetBLObject() method to inject a dependency for either type of BusinessLogic class:

 

   IBusinessLogic businessLogic = new ProductBL();

   BusinessFacade businessFacade = new BusinessFacade();

   businessFacade.SetBLObject(businessLogic);

 

Or:

 

   IBusinessLogic businessLogic = new CustomerBL();

   BusinessFacade businessFacade = new BusinessFacade();

   businessFacade.SetBLObject(businessLogic);

 

Posted 04-10-2009 4:36 PM by Padam Raj Gurung | with no comments

happy new year 2009

happy new year of 2009 to all Nepalese ...Wishing this MSDNNEPAL.NET would broadens our knowledges and helps us to cope our daily life of programming and able to develop new things on ourselves..in the days ahead..

Posted 01-01-2009 4:15 PM by Padam Raj Gurung | with no comments

ajax tricks validation !!

you might have gone through or not but i've recently faced and found out how ajax tricks validation control,,

the case is, i was developing a aspx form for one of my project where i have kept ajax calendar extender and required field validator for a textbox. and a button to save all the data entered and it was quite a long entry form...And I had a button control on which click event data would be saved in the db. To my surprise, when i run that form, it was not saving the data ...why?..then i started debugging...what i found  is that in each postback, though required field validator for the textbox was there..it deceived while submitting required field validator..the value was not present..oh ..it was the problem..Soon I found its remedy i put on update panel ,and it worked fine.....oneday you may come across like i faced, becareful...

Posted 12-31-2008 2:58 AM by Padam Raj Gurung | with no comments

Filed under: ,

jquery and UI templating!!

jquery could be very much helpful while performing templating i.e. rendering controls. 

I've followed the following steps for doing this.

1. on document ready function of jquery, I called its ajax behaviour.

 

 


  1. $(document).ready(function(){

  2.     $.ajax({
  3.         type:"POST",
  4.         url:"test.asmx/GetListData",
  5.         data:"{}",
  6.         contentType:"application/json; charset=utf-8",
  7.         dataType:"json",
  8.         success:function(msg){

  9.         $('#listData').removeClass('loading');
  10.         $('#listData').html(msg);
  11.     }
  12.     });

  13. });

 

 

 

2.  then, i created a usercontrol which contains datalist for templating.

on its code behind i wrote following code.

 

 

  1.          public object Data;
  2.         protected void Page_Load(object sender, EventArgs e)
  3.         {
  4.             DataList1.DataSource = Data;
  5.             DataList1.DataBind();
  6.         }

 

3. after that i created a webservice and passed the usercontrol path and data to ViewManager's Render method. This resembles with MVC which is booming in asp.net these days.

 

 

  1.  NorthWindDataset.CategoriesDataTable dt = new NorthWindDataset.CategoriesDataTable();

  2.             CategoriesTableAdapter da = new CategoriesTableAdapter();
  3.             dt = da.GetData();

  4.             if (dt.Count > 0)
  5.             {
  6.                 return ViewManager.RenderView("~/UserControls/listData.ascx", dt);
  7.             }
  8.             else
  9.             {
  10.                 return ViewManager.RenderView("~/UserControls/listData.ascx", null);
  11.             }

 

 

 

Finally, I ran my code. it worked great and superfast to asp.net ajax style. Just download the sample below and judge yourself.

 

download source code: jqajax.zip

 

Posted 11-03-2008 5:01 AM by Padam Raj Gurung | 1 comment(s)

Getting started with WWF

 it 's true, a single picture speaks thousand words. visual studio has this feature called work flow foundation to prove this in programming. Basically there are two type of work flows in visual studio . i) sequential workflow and ii) state machine workflow.

I'll show you, how to create a simple wwf application, and I start for simple file checking application where first,  i check for file either exists or not, after that i check its size and write proper message for UI.

1. create a WWF sequential class library project.

 

2. add a new item of sequential workflow(code) class. or you can use (XOML) either way.

 

3. add code activity and ifelse acitivity controls from toolbox and give proper name as below.

4. double click the code activity block and write your code there  to control your logic.

5. specify the if else condition using either declarative method or using code or both. I'm using both, below is declarative method.

 

5. Finally I used it in my windows form application. That's it. How easy it is!!

 

source code: wwf.zip

 

Posted 11-02-2008 1:46 AM by Padam Raj Gurung | with no comments

Code Generation Using Repository Factory!!

From the time, I've become familiar with Repository Factory, I've been continuously using it to generate my data access layer code. It has some few steps that i normally follow to successfully generate my data layer which contains business entities, stored procedures and repository classes. For this, i have installed DataAccessGuidancePackage.msi.

After installing guidance package, i create a class library project from my solution explorer. And then I choose Guidance Package Manager submenu from Tools mainmenu.

 

Then, I enable the guidance package manager and I select the Repository Factory CheckBox.

Now, I'm ready for generating code.Then, I right click the project and specify its reposibilities to be by checking all options as shown below.

After that, I add the database connection and it will generate app.config file for me.

Then, I select "Create business entities from database" option as shown above and select the tables for which i need to generate entities as below. It will generate properties for each field and class for each table.

 

Likewise, following the same process as above, I select the tables this time, for which I have to generate CRUD methods and, it'll generate SQL scripts for me which i run in MSSQL database.

 

Finally, most important is that, I select option to create repostiory classes. It will generate a whole bunch of classes within a minute. If I've to write those code, it would take weeks for me, though my typing speed is not so poor.

 It has helped me very much. Now, I can use this repository classes to directly bind data with data controls in presentation layer or just use in business object layer. Why not try yourself ..?

 

 

 

 

Posted 10-17-2008 2:25 AM by Padam Raj Gurung | 2 comment(s)

Filed under:

My First MVC Test Application!!

This is my first mvc test application and it is very  simple to startwith. I have heard and read about MVC in blogs and websites two or more times, but I still haven't  tested it. But, today, I find it quite interesting and efficient to my previous asp.net techniques. I have tested this application in CTP 3 release of MVC.

First of all, I created a MVC web application from the New project sub menu.

 

Then, I created table named task and generated its LinqToSql O/R mapping class.

 

After that, I wrote public functions in the Home controller class.

After that, I created 'Index' view

 

and 'Create' view.

 

Finally, When I have run my code, it worked excellent.

Download source code: FirstMVCApp.zip

 

Posted 10-11-2008 12:23 AM by Padam Raj Gurung | 1 comment(s)

Filed under:

DataTable has lots of cool features!!

Many of us proabably haven't used the coolest features provided in DataTable. I was also unknown to its features previously. I came across this features one day, when i just roaming in search engines.

Some features, I like most are listed below.

1. I can directly load the SqlDataReader by using the load method of datatable. So I don't need to use data adapter any more.

e.g. DataTable dt = new DataTable();

dt.Load(sqlDataReader);

2.  It can be used directly as a datasource as well. e.g.  dt.CreateDataReader();

3. It has functions like ReadXML, WriteXML, ReadXmlSchema, WriteXmlSchema...to work with XML file directly.

4. I can use FindBy<Primarykey> method to get the particular data row.

e.g ProductDataRow dr = dt.FindByProductID(proID); //search

5. I even can select filtered datarows.. sort by fieldname.

e.g. DataRows[] rows=  dt.Select("Price>100", "ProductName");//filter and sort

6. I even can compute sum, average...without iterating datatable.

e.g. decimal totalAmount = dt.Compute("Sum(ProductPrice)",String.Empty);//sum

 

Ya...very nice features.

These are most common functions I use and there are lots more...They are type safe, and has user friendly functionalities like sorting, filtering, searching etc. I really enjoy using these functionalities of Typed dataset and datatable provided by ADO.NET.

 

Posted 10-09-2008 1:43 PM by Padam Raj Gurung | with no comments

Filed under:

System.Transactions best for SQL 2005!!

In .net framework 2.0, a new namespace has been introduced, called System.Transactions. I have been able to greatly reduce my code for doing SQL transaction.

The code goes like this.

 

Using System.Transactions;

using (TransactionScope scope = new TransactionScope())

{

    using(SqlConnection conn = new SqlConnection(connString))

   {

       SqlCommand cmdInsert = conn.CreateCommand();

       cmdInsert.CommandText="INSERT INTO...";

       SqlCommand cmdUpdate = conn.CreateCommand();

       cmdUpdate.CommandText="UPDATE .....";

      cmdInsert.ExecuteNonQuery();

      cmdUpdate.ExecuteNonQuery();


   }

   scope.Complete();


}

Whenever I've to work for SQL 2005, I don't miss to use TransactionScope. Its short and simple.



 

Posted 10-09-2008 12:33 PM by Padam Raj Gurung | with no comments

Filed under:

My web page lost intellisense!!

I was in much poblem from last few days. When I use masterpage and visual studio 2005 with ajax enable website. Anything that goes inside content template of update panel lost intellisence. But when it was viewed in browser, it worked well. I was in great trouble to troubleshoot this problem. Have you ever face this kind of problem?

May or maynot....After googling a lot, finally, I got soution from Scott Guthrie.

He has  posted two solutions for this:

1. First, you kept open your master page in solution when you are working with other pages derived from this master page, this gives intellisence to your webpage. But this is not best solution.

2. Second is that, you should install VS 2005 SP1, this problem will be automatically solved.

 

Finally, I got solution. Thanks Scott.

 

 

Posted 10-08-2008 1:00 PM by Padam Raj Gurung | 1 comment(s)

Filed under: ,