Tuesday, December 22, 2009

Acccessing User control in Class Library Project in ASP.NET

Hi All,

In one of scnerio. i have to access user control of web application in my Class Library project.I do check what are the possibilities and alternatively found the solution.

Solution:

Implement interface to user control and get access of properties and methods in class library.

   23 public partial class multiupload : Imultiupload


{
...
}

here is my Interface

    9 public interface Imultiupload


{
...
}

in my Class Library project class where i want to access i have just initialize the control like this,

   41 Imultiupload fileupload = null;



and then i have access it by LoadControl method.

  314 fileupload = (Imultiupload)Page.LoadControl("~/inigo/admin/controls/multiupload.ascx");

  315                             fileupload.ControlID = Lib.ToUnderscore(p.Name);

  316                             fileupload.AllowMultipleFileUploads = true;

  317                             fileupload.ButtonText = "Upload Files";



Using Interface to access the user control in class library project is good practice.

Happy Coding :-)

Saturday, December 19, 2009

Make your Class Lib project as Web Application Project

Hi All,

In one of my requirement i have to put my user control to Class Lib project. so i have digs a net and found the solution with something unbelievable.to achieve this please follow given steps,

1) Unload Class Lib project.
2) Edit Class Lib project and add following under very first line of ProjectGuid element

{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}

3) Once done with above Reload the project and Finish..!!

now when you select 'Add New Item' you will get all required web files there. once you rebuild it will available with single class assembly dll.


Happy Coding :-)

Friday, December 11, 2009

Show enum with space {If you are using Pascal case for Data}.

Hi All,

for a long period i was looking for some solution to allowing space in Enum to show Friendly while Displaying.

after digging too much i have come up with solution. I was using Pascal casing for strings shown in Enum, so here i have done some logic,

static string ToFriendlyCase(this string EnumString)
{
return Regex.Replace(EnumString, "(?!^)([A-Z])", " $1");
}

so if you Enum is TextField it will show you as "Text Field".

Happy Coding :-)

Sunday, December 6, 2009

Find any keyword stored inside MS-Sql 'Function' or 'Procedure'.

Hi All,

As developer, one have frequently facing with problem of finding function or procedure in which they have made change. Here is how you will find out any keyword which you are looking for..

SELECT ROUTINE_NAME, ROUTINE_DEFINITION
FROM INFORMATION_SCHEMA.ROUTINES
WHERE ROUTINE_DEFINITION LIKE '%KEYWORD%'
AND ROUTINE_TYPE='PROCEDURE' -- Write 'FUNCTION' to search in function.
ORDER BY ROUTINE_NAME

Happy Coding :-)

Friday, December 4, 2009

Show Edit Form Open with Telerik RadGrid with Insert button click.

Hi All,

My requirement for one event related to Telerik RadGrid for asp.net is i need to facilitate users to see Detailed Form when Master Record is inserted within same page.

So, here is my solution for this, in my case postback event is raised so i need to check with IsPostBack, below is code snap to be used for.

1) you need to register that event like with below code

132 this.rgformFields.PreRender += new EventHandler(rgformFields_PreRender);


2) above code which auto generate protected method which looks like below,

110 protected void rgformFields_PreRender(object sender, EventArgs e)

111 {

112 if (IsPostBack)

113 {

114 rgformFields.MasterTableView.IsItemInserted = true;

115 rgformFields.Rebind();

116 }

117 }



rgformFields is RadGrid of Telerik suite. I hope this could solve problem/requirement.

Happy Coding,

Stored procedure to generate Inserts from Table in MS-Sql

Hi All,

"Narayana Vyas" have given all of us a very good stored procedure which will generates insert scripts from tables.

Please find it here, or mail me i will send it you on reply.

http://vyaskn.tripod.com/code/generate_inserts.txt

Happy Coding :-)

Thursday, December 3, 2009

Compare and extract difference string from two string[].

Hi,

In my one requirement i have to compare difference between two string[] through which i can justify missing headers.

.net have Dictionary class which i have used to solve my requirement.

below is code snippet how,

385 Dictionary<string, int> diff = new Dictionary<string, int>(StringComparer.InvariantCultureIgnoreCase);

386 foreach (string s in _strHeadersNames)

387 diff[s] = 1;

388 string[] strvalues = IsColumnHeadersExist(_strHeadersNames, strCsvFilePath).Split(',');

389 if (strvalues.Length > 1)

390 {

391 foreach (string s in strvalues)

392 {

393 int value;

394 if (diff.TryGetValue(s, out value) && value != 2)

395 diff[s] = 3;

396 else

397 diff[s] = 2;

398 }

399 foreach (KeyValuePair<string, int> pair in diff)

400 if (pair.Value == 1)

401 _strDiff = string.Concat(_strDiff, pair.Key, ",");


I hope above will be useful to you.

Happy Coding:-)