Sudarsan Dash's Blogs on C, C++,C# , .Net and Jquery
Life is a Short Span, try to earn knowledge in every Field.
Tuesday, 11 March 2014
Tuesday, 18 February 2014
How to open a new tab On click of a hyper-linked column in Telerik Razor Grid
Today i got a requirement to open a external URL in a tab when the linked column is clicked.
This can be achieved by simply adding the client template/ template to the linked column.
1) Using Template Attribute in the Telerik Grid
2) Using Client Template Attribute in the Telerik Grid
Output:
But the really annoying is that when you click the link it is throwing error as
"The resource you are looking for has been removed, had its name changed, or is temporarily unavailable"
This is because the IIS is unable to resolve the path.
Solution to the above issue:
The above issue can be fixed by a simple trick, just you need to append the http:// to the website in the client template or in the template attribute. See the code below:
This can be achieved by simply adding the client template/ template to the linked column.
1) Using Template Attribute in the Telerik Grid
column.Bound(a => a.Website) .Template(@<text><a href="@Url.Content(item.Website)" target="_blank">@item.Website</a></text>) .HeaderTemplate( @<text> <a href="javascript:void(0)" class="t-link" orderby="Website">Website</a> @Html.TextBoxFor(m => m.Filter.Website) </text>);
2) Using Client Template Attribute in the Telerik Grid
column.Bound(a => a.Website) .ClientTemplate("<a href='<#= Website #>' target='_blank'><#= Website #></a>") .HeaderTemplate( @<text> <a href="javascript:void(0)" class="t-link" orderby="Website">Website</a> @Html.TextBoxFor(m => m.Filter.Website) </text>);
Output:
But the really annoying is that when you click the link it is throwing error as
"The resource you are looking for has been removed, had its name changed, or is temporarily unavailable"
This is because the IIS is unable to resolve the path.
Solution to the above issue:
The above issue can be fixed by a simple trick, just you need to append the http:// to the website in the client template or in the template attribute. See the code below:
column.Bound(a => a.Website) .Template(@<text><a href="@Url.Content("http://"+item.Website)" target="_blank">@item.Website</a></text>) .HeaderTemplate( @<text> <a href="javascript:void(0)" class="t-link" orderby="Website">Website</a> @Html.TextBoxFor(m => m.Filter.Website) </text>);
Note: Similarly if it is a mail ID column then, use mailto: as the prefix.
Thats it, Enjoy!
Sunday, 12 January 2014
How to Add Re-ordering of the columns in Telerik MVC or Razor Grid.
Some times it is required that the column had to be re-ordered in a grid as, we are using a Telerik grid , as adding the property reorder will do the task.
Here is the code below to do it:
Here is the code below to do it:
.Reorderable(reorder => reorder.Columns(true))
Just add this line to your Telerik Razor grid, it will do the task.
Happy Coding!
How to show the Pager in Telerik Grid both in top and bottom.
While working in a project , my client wants to show the paging in the grid in both in the top of the grid as well as in the bottom of the grid also. As I am using the Telerik grid, it has a property to set while creating the grid.
So here is the code for it:
So here is the code for it:
Happy Coding!.Pageable(p => { p.Style(GridPagerStyles.NextPreviousAndNumeric | GridPagerStyles.PageSizeDropDown);
p.Position(GridPagerPosition.Both); // this line will do the Magic p.PageSize(int.Parse(ViewBag.PageSize ?? "50"), new[] { 10, 20, 50 }); }).Sortable()
Monday, 23 September 2013
How to Insert space before capital letters using Jquery
Assume you have a string "HelloWorld" and you need to show as "Hello World". How you can achieve it using Jquery.
It can be done in a very simpler way as below:
"Your string".replace( /([a-z])([A-Z])/g, "$1 $2")
so here it will be "HelloWorld".replace( /([a-z])([A-Z])/g, "$1 $2") will produce "Hello World"
Enjoy!
It can be done in a very simpler way as below:
"Your string".replace( /([a-z])([A-Z])/g, "$1 $2")
so here it will be "HelloWorld".replace( /([a-z])([A-Z])/g, "$1 $2") will produce "Hello World"
Enjoy!
Wednesday, 17 July 2013
Differentiate between 'All' and 'Any' Operators in LINQ.
In LINQ, All operator is to check whether all the elements met the specific condition or not. While Any operator checks whether there is any element exist in the collection or not.
For Example:
int array={1,2,3,4,5};
bool result=array.All(i=>i < 6); here it will check the elements and returns true.
Similarly,
bool result= array.Any( ); // here it checks whether the collection has any elements and returns true.
Hope you Enjoyed!
For Example:
int array={1,2,3,4,5};
bool result=array.All(i=>i < 6); here it will check the elements and returns true.
Similarly,
bool result= array.Any( ); // here it checks whether the collection has any elements and returns true.
Hope you Enjoyed!
Monday, 15 July 2013
Compile Time View Checking In Asp.net MVC
You might have noticed that in MVC3/MVC4 if you had done some thing wrong in the view files it will not throw any error during compilation and it will build successfully. The error in the file is only noticed during executing/rendering the view file. So in order to trap the error during the compilation time you can follow the method below:
Step-1 :
Open your solution project file in any XML Editor or in the Visual Studio itself and you will find a tag named
<MVCBuildViews>, here it false and just make it true and save it.
<MVCBuildViews>false</MVCBuildViews>
change it to
<MVCBuildViews>true</MVCBuildViews>
Thats all, so now when your view has any error then it will throw error during the compilation.
Step-1 :
Open your solution project file in any XML Editor or in the Visual Studio itself and you will find a tag named
<MVCBuildViews>, here it false and just make it true and save it.
<MVCBuildViews>false</MVCBuildViews>
change it to
<MVCBuildViews>true</MVCBuildViews>
Thats all, so now when your view has any error then it will throw error during the compilation.
The Use of ALL Operator in LINQ
Today, I came across the All operator in LINQ. This operator returns bool value rather than records after condition is satisfied. The operator will be highly helpful when you need some kind of validation to find unique data. for e.g. Checking the existing email or UserID registered and so on.
Lets Go with a Example to do the Task:
int [] array = { 1,2,3,4,5 };
bool result = array.All(value => value > 2 );
Console.WriteLine(result); // Here it will print False since it will check all the values and // all the values must be grater than 2.
result = array.All(value => value < 6 );
Console.WriteLine(result); // Here it will print True since it will check all the values and // found all values are less than 6.
Hope it helps you!
Lets Go with a Example to do the Task:
int [] array = { 1,2,3,4,5 };
bool result = array.All(value => value > 2 );
Console.WriteLine(result); // Here it will print False since it will check all the values and // all the values must be grater than 2.
result = array.All(value => value < 6 );
Console.WriteLine(result); // Here it will print True since it will check all the values and // found all values are less than 6.
Hope it helps you!
Monday, 17 June 2013
Error 349: Duplicate headers received from server in Google Chrome while rendering PDF using ITextSharp in Asp.Net MVC
While working on generating PDF in Asp.Net MVC3, I got a peculiar error while rendering the PDF in Chrome browsers, which is not being found in any other browsers like Internet Explorer or Fire Fox.
This error comes because chrome browsers doesn't ignore duplicate headers. This can be addressed easily the following ways, if you or your web app is sending out headers. Then check the following things:
1. Enclose fileName using “”. i.e
Response.Addheader('Content-Disposition: attachment; filename="' + fileName '"');
instead of
Response.Addheader('Content-Disposition: attachment; filename='+ fileName);
2. If possible replace spaces and commas (,) with underscores (_)
string regExp = @"[^\w\d]";
Response.AddHeader("content-disposition", "attachment;filename=" + "Test_PDF_" + Regex.Replace(model.CompanyName, regExp, "_")+ "_" +
Regex.Replace(model.FullName, regExp, "_") + "_" + DateTime.Now.ToShortDateString());teString());
3. Explicitly tell Asp.Net MVC to override headers by setting optional replace parameter to true.Response.AddHeader("Content-type: application/pdf",true);
Happy Coding!
Labels:
Asp.net,
Asp.net / C#,
Itextsharp,
JavaScript,
MVC3,
MVC4,
Razor,
Telerik MVC grids,
Tips and Tricks
Location:Mayur Marg, Begumpet, Hyd-16, India
The Hyderabad Public School, Mayur Marg, Begumpet, Hyderabad, Andhra Pradesh 500016, India
Friday, 14 June 2013
How to prevent the multiple submit of record in ASP.Net MVC using JQuery
There are various methods are available to do that one, it can be done using JQuery, using sessions or Filters.
Method -1 ( Using JQuery Approach)
This is the simplest method to prevent the multiple submission of the record in MVC and even it works on JQuery Unobstructive validations.
Happy Coding!
Method -1 ( Using JQuery Approach)
$('form').submit(function () { if ($(this).find('.input-validation-error').length == 0) { $(this).find(':submit').attr('disabled', 'disabled'); } });
This is the simplest method to prevent the multiple submission of the record in MVC and even it works on JQuery Unobstructive validations.
Happy Coding!
Labels:
Asp.net / C#,
Hacks,
Itextsharp,
JQuery and CSS,
MVC3,
MVC4,
Razor,
Tips and Tricks
Location:Mayur Marg, Begumpet, Hyd-16, India
The Hyderabad Public School, Mayur Marg, Begumpet, Hyderabad, Andhra Pradesh 500016, India
Subscribe to:
Posts (Atom)