Showing posts with label ASP.NET. Show all posts
Showing posts with label ASP.NET. Show all posts
Friday, August 2, 2013

How to add a control to user control from a web page in asp.net

This post in a reply to a question on stackoverflow.com. Where the person who asked this question want to add control from the asp.net page dynamically. I decided to write a blog post here.

So let’s first create a user control for this.

MyUserControl

After creating a user control It’s try to put the user control in the aspx page like following.

Share:
Saturday, July 13, 2013

Compile time view checking for ASP.NET MVC.

While developing an ASP.NET MVC application, you need to create lots of views. At that time it does not compile the view. So if you have some typo in your view like namespace or any where you will get to know when you load that view in browser. At that time ASP.NET Complier will compile the complete view. 

We all are humans and we tends to make spelling mistakes and sometimes it a productivity loss when you create a very big view or complicated view. So I was searching on internet that whether there is a tool available to compile view also. After digging into it. I have found that there is a setting where we can tell whether its compile view or not. So once you enable that settings It will also compile views.
Share:

Programmatically Hiding ASP.NET Grid View Column.

Recently I have been to http://forums.asp.net/ and found that lots of people are finding solution for hiding the Grid View column so I though it will be a good Idea to write a blog post. In this post I will explain how we can hide GridView Column programmatically. So let’s take same example that I have taken in previous post.

Hide ASP.NET GridView Column:


So let’s take  a simple example. I am going to bind a grid with list of Employee class and then on a button click I am going to hide the first column of grid. Following is a HTML code for that.
<div>
    <asp:Button runat="server" Text="Hide Column" ID="btnHideColumn" OnClick="btnHideColumn_Click"/>
</div>
<div>
        <asp:GridView runat="server" ID="employeeGrid" AutoGenerateColumns="False">
            <Columns>
                <asp:BoundField HeaderText="Employee Id" DataField="EmployeeId"/>
                <asp:BoundField HeaderText="First Name" DataField="FirstName"/>
                <asp:BoundField HeaderText="Last Name" DataField="LastName"/>
            </Columns>
        </asp:GridView>
</div>


Share:
Saturday, July 6, 2013

Dynamically setting GridView Column width in ASP.Net

I was looking into the forums.asp.net and I have found lots of people was searching about how to set GridView Column Width dynamically. So I thought it will be a good idea to write a blog post about it.

Example(Setting Width Dynamically in ASP.Net):


So let’s take a an example for that. For that I have created a small model Employee class which will have three properties.
public class Employee
{
    public int  EmployeeId { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
}

Share:
Sunday, June 9, 2013

Creating PDF with ASP.Net MVC and RazorPDF

Update: I have written a new blog post about better approach to create a PDF with asp.net mvc- You can find that following location.- A Better Solution to create PDF with Rotativa and ASP.NET MVC

In this post we are going to learn how we can easily create PDF from ASP.Net application with the help of Razor PDF NuGet package.

About Razor PDF:


This NuGet package is created by Al Nyveldt It internally uses ITextSharp an open source PDF convertor library. RazorPDF uses Razor View engine to create iTextXML which is in tern used to produce PDF file. You can get more information about that at below link.

https://www.nuget.org/packages/RazorPDF

Example(Creating PDF with ASP.Net MVC):


So what we are we waiting for ? Let’s create a simple example. To create example first thing we need to a create and ASP.Net MVC application.
Share:

Horizontal and vertical scrollbar in HTML5 and CSS3

In this post we are going to learn how we can put horizontal and vertical scrollbar in HTML5 and css3. In earlier version of HTML and CSS if we have to put only horizontal or vertical scrollbar that was not possible. Because there was no such properties there in CSS to describe whether we have horizontal scrollbar or vertical scrollbar.

Scroll bar in earlier version of HTML and CSS3:


In earlier version of HTML and CSS we have to use overflow property to display scrollbar for a particular div tag and If we add scrollbar it will add both horizontal and vertical scrollbar even if there is no need for that.Following is a code for that.
Share:
Saturday, June 8, 2013

Rounded corner div with HTML5 and CSS3

I have been recently playing with HTML5 and CSS3 and it is really fun. I am learning lots of new features of HTML5. Rounded corner is one of them. I thought it will be a good idea to share that with my readers. So In this post we are going to learn how we can create rounded corner div with HTML5.

In earlier version of HTML and CSS, If we need rounded corner div then we all needs to use image and without image it was not really possible. But now with the HTML5 and CSS3, It is very easy to create round corner div.

How to apply round corner to div?


There is a new CSS3 declaration for that. Border-Radius, With this you apply round corners to boxes and div without using images for rounded corners.

Example:


Let’s create an example for rounded corner div. I have created an sample page with Visual Studio 2012.

Rounded Corner div html5 and css3
Share:
Sunday, June 2, 2013

How to call ASP.Net page method with jQuery

In this blog post we are going to learn about how we can call asp.net page methods from jQuery.

What is ASP.Net Page Method?


Page methods are available from ASP.Net 2.0. It’s an alternative to web services in ASP.Net application. This methods are exposed at client side and you can call that page methods directly from JavaScript.It is an easy way to communicate asynchronously with the server using Ajax.

Creating a page method:


So for creating a page method let’s create a asp.net web empty web application.

Calling asp.net page methods with jquery
Share:
Monday, May 6, 2013

Unobtrusive validations in ASP.Net 4.5 Web Forms

With the release of ASP.Net 4.5 web forms there are tons of features added in the ASP.Net and Unobtrusive validations support is one of them. We have already seen that kind of validation in ASP.Net MVC and now we are going to have that in ASP.Net web forms. In this post I am going to explain how its works and how its different from earlier versions.

How validation was working with earlier versions?


In the earlier versions of ASP.Net it was working via putting a JavaScript for that. Let’s take a simple example. I have putted three things here. A textbox, required field validator and a button like following.

Share:
Friday, May 3, 2013

Server.Map alternative in WCF - HostingEnvironment.MapPath

If you are ASP.NET programmer then you already know about Server.MapPath. It is used to map a physical location on webserver for asp.net.  You can find more information about Server.MapPath from the following location.

http://msdn.microsoft.com/en-us/library/ms524632(v=vs.90).aspx

You can still use that in WCF(Windows Communication Foundation) service http bindings. As we know WCF Service can use other non http bindings like TCP/IP,MSMQ and Named Pipe. At that time HttpContext of WCF will be none so server.mappath will not be available as current context is not available. Because its a child class of HttpContext.Current.

HostingEnvironment.MapPath :


HostingEnvironment.MapPath works on all kind of bindings. So when you have other bindings like TCP/IP and MSMQ it will be available as it is inherited from the System.Web.Hosting namespace. You can find more information from below MSDN link.
Share:
Sunday, April 21, 2013

Server.MapPath variations

Those are working on in web technologies like ASP.Net and ASP are already familiar with server.MapPath method.  It is used to Maps a virtual or relative path to a physical path. Recently I had discussion with my friends what kind of options we have for Server.MapPath and We have discussed lots of things. So I thought it will be a good idea to write a blog post about it. I know this is very basic but sometimes we were not aware about basic things. So following are different kind of options we have with Server.MapPath.
  • Server.MapPath("~") return the root physical path of application.
  • Server.MapPath(“.”) returns the current physical path of a executing file(i.e .aspx file)
  • Server.MapPath(“..”) returns the current physical path of parent directory of executing file.
  • Server.MapPath("/") returns the he physical path to the root of the domain name
It’s very basic so if you try first one. It will load c:\users\lenovo\documents\visual studio 11\Projects\WebApplication1\WebApplication1\

It’s very easy hope you like it. Stay tuned for more.
Share:
Thursday, April 11, 2013

Two free spell checker extension for visual studio 2012 every developer should use

We all are humans and we tends to make mistakes. I am personally take care about lots of spelling mistakes when writing code but sometimes we don’t identify whether there is a spelling mistake there or not. At that time this spell checker extensions come handy.There are plenty of options available for spell checker extensions but In this post I am going to explain those two free spell checker plugins that I am using.

Spell Checker by Noah Richards:


This is a excellent plugin for identifying the spelling mistakes. You can download plugin from following url.

http://visualstudiogallery.msdn.microsoft.com/7c8341f1-ebac-40c8-92c2-476db8d523ce

It’s provides spelling checks for almost all the files.
  1. Plain text files where entire file will be checked for incorrect spelling.
  2. Source code(.cs files)
  3. HTML/ASP files.
For each spelling error, the user is presented with a list of alternative spellings, via a smart tag (activate with ctrl+.), and the option to ignore the word or add it to the user's dictionary.

You can configure the color of the squiggle under misspelled words by changing the foreground color of Spelling Error (in Tools->Options->Environment->Fonts and Colors).  The default color is red. Following is a example for that.

SpellChecker
Share:
Monday, March 25, 2013

ASP.NET 4.5 TextBox TextMode Property

Right now everybody is talking about HTML5 and its contains lots of new features like web sockets, canvas, new intput types with validation etc.

ASP.NET 4.5 text mode property enhancement:


With HTML5 new input types is going to be one of coolest feature and in future more and more people are going to use that feature. So in asp.net 4.5 asp.net development team given a support via TextMode property enhancements.

In earlier versions of ASP.NET we used have only three properties for TextMode property of asp.net textbox control.
  1. MultiLine- for multiline textbox.
  2. Password- for password textbox
  3. SignleLine –for single line textbox
With ASP.NET 4.5 you are going to have tons of options with TextMode property.
  1. Color- for Color entries
  2. Date-  for date entries. You can enter dates only
  3. DateTime – for datetime entries with respect to local time zone.
  4. DateTimeLocal- for datetime entries with respect to local time zone.
  5. Email- for email address
  6. Month- for month and year entry.
  7. Number- for  entering numeric values.
  8. Range- for containing range between two numbers.
  9. Search- for search field. A search field is like regular text fields
  10. Tel- for telephone number.
  11. Url- for website url entries. It will only contain urls.
  12. Week- for entering weeks and year.
Share:
Friday, March 22, 2013

My blog post appears on asp.net community spot light

Once again my blog post about CRUD operations with asp.net and petapoco appears on the Microsoft asp.net official website. I would like to thank you all for specially Jon Galloway and asp.net team.

ASPnet

A big thank you for every one for supporting me.
Share:
Wednesday, March 13, 2013

Default focus and default button in asp.net

Sometimes ago a friend ask me how to put default focus and default button in ASP.NET. He was not knowing that there is property for that in form tag in asp.net. I thought it will be good idea to write a blog post about that.So those who are not aware of this feature can get an idea for that.

In some cases we need to have default button and default focus. For example take a example of a shopping cart registration form. Where you need to have default focus into the first textbox if you contain list of textboxes over there. Same way you can have more then one button on asp.net forms for example save and cancel so once user press enter which button should be pressed. On above both scenario this Default button and default features can come very handy.

From asp.net 2.0, The form tag has this two properties DefaultButton and DefaultFoucs where you can set the Id of control that you need as default button and same way you need to put Id of a control for default focus.
Share:
Sunday, March 10, 2013

How to consume ASP.NET WebAPI from jQuery

Before some months Microsoft has launched WebAPI framework for building and consuming HTTP services. This WebAPI can be called from anything like from mobile sites to JavaScript anything. I thought it will be a good idea to call a WebAPI from jQuery.

In this post I am going to explain how to consume ASP.NET WebAPI from jQuery.

Creating a basic WebAPI:

To create a web API you need to install ASP.NET MVC 4.0 and then you create a new project for MVC .

How to Create Webp API in Visual studio 2012

Now once you click Ok. It will ask for type of project. You want to create you need to select Web API there.
Share:
Thursday, March 7, 2013

SelectMethod in ASP.NET 4.5 Model binding

New version of ASP.NET provides lots of way of binding data to the data controls like Grid View, Repeater etc. You can now bind this controls with strong type. I have earlier written a blog post about How we can use Model binding with ASP.NET 4.5 and Visual Studio 2012.

SelectMethod in ASP.NET 4.5:


In asp.net 4.5, It is also possible to bind controls with SelectMethod attribute. This method specify the data that you want to bind with data controls like grid view and repeater controls.

So what we are waiting for?? Let’s take an simple example. I have create a basic model class “Employee” like below.
public class Employee
{
    public int EmployeeId { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
}
This class contains three properties EmployeeId,FirstName and LastName. Now I have created one method to get a generic list of employee model like following.
Share:
Wednesday, March 6, 2013

Tip- InProc session state was not working with IIS7.5

In this post I am going to explain about reason for InProcsessionState was not working with IIS 7.5.

Problem:

Yesterday in one of my PC I got updated IIS 7.5 and suddenly after updating the IIS my ASP.NET application session state stopped working. It was a very weird behaviour and after doing some R and D I have found that my worker process per application was more then one.

That was the reason for the  session state was not working as “InProc” session state is using IIS memory to manage sessions.  You can find more information about this in following link.

http://stackoverflow.com/questions/2147578/asp-net-session-state-and-multiple-worker-processes

Resolution:

There are two ways of resolving this problem.

1) You can use other session state mode like State Server or SQL server which supports multiple worker processes.
Share:
Thursday, February 7, 2013

Redirection with ASP.Net friendly URLs

In this post we are going to see how we can use Response.Redirect(Redirecttion) in asp.net friendly URLs. Before some day I have written a post about ASP.NET Friendly URLs – Cleaner, SEO friendly URLs. On that post one reader ‘Ramesh’ asked me that how we can do redirection with ASP.Net friendly URLs. So this post is in reply to Him.

How to redirect a page to ASP.Net friendly URLs:

Actually!! there is nothing to learn. It’s very easy You can directly use the ‘Response.Redirect’ with the ASP.Net friendly URLs. The NuGet Package itself takes care of all the things. You just need to write the route name as a parameter in ‘Response.Redirect’ and you are done!!

Uh!! don’t believe me!!. Let’s take a sample example. I am going to use by default template with ASP.NET Friendly URLs.  So for this example I have created a ASP.Net button in Default template AboutUs.aspx page. Once the click of that button we are going to use ‘Response.Redirect’ for redirection and redirect this page to Contact Page. Following is a html code for that button.
Share:
Monday, February 4, 2013

ASP.NET Friendly URLs – Cleaner, SEO friendly URLs

Search Engine optimization is one of the key factor for your site. If you spend millions of dollars on making your website looks good and bug free then also its possible that you will not get attention of search engine because of your URLs.  For example you’re having shopping cart created in asp.net and you have not optimized your URL then it will look like following.

www.foo.com ?Product.aspx?Category=1& Page=1

If you search engine read this URL then search engine will not know much about this URLs. Even normal people  who does not know querystring menaing(?Category=watch&Page=1) will not understand it. But If you have URL like following.

www.foo.com/prduct/category/watch/page/1

It’s easy to read and search engine and normal people will know that you are loading products that belongs to category watch and this is a first page.
Share:

Support this blog-Buy me a coffee

Buy me a coffeeBuy me a coffee
Search This Blog
Subscribe to my blog

  

My Mvp Profile
Follow us on facebook
Blog Archive
Total Pageviews