Development Desk

Just another WordPress.com site

Category Archives: Asp.Net development

Severity Code Description Project File Line Suppression State Error Cannot open ” The requested operation cannot be performed on a file with a user-mapped section open.

Sometimes visual studio throw this error because it cannot open dll file to write. I fixed this issue by deleting the dll file in the debug folder. You might not be able to delete the file by going to the debug folder there it has to be deleted from Command Prompt forcefully.

  • Open Command Prompt in Admin mode
  • Navigate to debug folder like cd ‘c:\my source code\project\bin\debug\’
  • then del /f fillname

Thank you

OnClick Event for Text Box in ASP.NET with C#

these 2 statement realy works no need to write in textbox field just write these two statements

1st one is code behind in PageLoad

TextBox1.Attributes[“onclick”] = “clearTextBox(this.id)”;

and 2nd is in aspx in header

function clearTextBox(textBoxID)
{
document.getElementById(textBoxID).value = “”;
}

thank you

Solution for Exception: System.InvalidOperationException: Data source is an invalid type. It must be either an IListSource, IEnumerable, or IDataSource.

This exception occurs when we assign DataSource to some DataGrid or Calender and after that try to bind that DataSource with that Control.  Actually the  Problem is, Control like Gridview requires a collection to be bound with them instead of on single Object

suppose you have a Person class you fetch 1 single person from database like in below case person data is fetched by the method in the business Logic layer on the base of person id

Person singlePerson = new personBL().getSinglePerson(personId);

and then

personGridView.DataSource = singlePerson;

personGridView.DataBind(); // on this point exception will be thrown because single Instance of class is assigned to Gridview

it can be resolved, if you have only single object to assign you can simply add it to the list then assign to the DataSource like

 

Person singlePerson = new personBL().getSinglePerson(personId);

List <Person> personList = new List<Person>();

personList.Add(singlePerson );

personGridView.DataSource = personList;

personGridView.DataBind();

or

simply assign a collection instead of on single instance of object to resolve it

it just simple is that.

thank you

ASP.NET Master Page Controls, Contents or methods make available to all Derived pages.

Referencing Custom Master Page technique could be very help in the situation in which you want to access some master page to its Content pages e.g. User open a website and He/She gets Login to website now you needs user ID on every derived page to use or fetch some information from the database. It can be done in few easy steps

1. In Master page (Code behind file) make public property

public String UserID

{

get{ return (String)Session[“UserIdNumber”]; }

set{ Session[“UserIdNumber”] = value; }

}

2. After all @Page Directives properties Add @ MasterType declaration

<%@ Page Language = “C#” MasterPageFile = “~/Interface.master” …. %>

<@ MasterType VirtualPath = “~/Interface.master” %>

3. now simply Reference the Master page Property from the Content Page

e.g.

String userId = Master.UserID;

it was the overall procedure to use this technique to set one property and accessible for all content pages.

to access control in child page FindControl method can be used

this code should be in Page_Load method and master page control must be public

Label lblUserID = (Label)Master.FindControl(“lblLoginUserID”);

lblUserID.Text = “Any value :-)”;