ASP.Net

ViewData, ViewBag, TempData and Session in MVC

ViewBag, ViewData, TempData and Session are the options to send value from controller to view or to other action method/pages. ViewData and ViewBag are very straight forward, they used to send the data from controller to view and done but in case of TempData and Session we can pass values from controller to view and even we can get our value from other pages after redirecting. As we know TempData... By Ali Adravi   On 15 Nov 2014  Viewed: 4,538
  • mvc
  • asp.net

Check/Uncheck all checkboxes in asp.net by javascript

I was searching for select/deselect all checkboxes code into a gridview. I found most of them only provide to select and deselet all the checkboxes if any of the checkbox is unselected into grid the main checkbox is not affecting. I further try to search some useful code but could not found any useful solution, some of them are selecting all the checkboxes on the page or some provides only to... By Ali Adravi   On 10 Jul 2012  Viewed: 4,372
  • asp.net
  • javascript

Linq to SQL connection String to read from web.config file automatically

When we use Linq to SQL it creates a connection string in Settings files. When we need to create the DLL of the DataAccessLayer (DAL) for production server or any server which is not our current development server then we need to change connection string manually in Settings file, is not it would be good to set something in application so it can always read the connection string form web.config... By Montana Neyra   On 17 Jun 2012  Viewed: 3,697
  • linq to sql
  • web.config
  • asp.net

Different action for different buttons from a single page in MVC

To post from different buttons on a single MVC page to different action methods, we need some extra code. We need to create an attribute class by inheriting ActionNameSelectorAttribute and override IsValidName method. We will use the button name to call any particular action on the basis of button name. It looks some thing very difficult but in reality it is more than easy. Let's creat our... By Ali Adravi   On 26 Apr 2015  Viewed: 3,528
  • mvc
  • razor
  • attributes
  • asp.net

Array in C# - single, multiple and jagged array

An array can be initialized in several ways, it can store a single value or series of values, every element must be set of same type, C# supports single-dimensional arrays, multidimensional arrays (also call rectangular array) and array-of-arrays (referred jagged arrays), let’s discuss features of array in C# like how to declare array in C#, How to initialize values to an array, how to define the... By Ali Adravi   On 24 Mar 2013  Viewed: 3,510
  • c#
  • array
  • asp.net

Read write xml in asp.net c#

Reading and writing in xml can be done in different ways, some common classes people use are XmlTextReader, XmlTextWriter , XmlDocument but we will use XDocument. By using the other classes say XmlTextReader we need to use the while loop to read and check every node by using XmlNodeType, for a long XML file which is not suitable. We need a way to search the exact node by providing Id of the... By Ali Adravi   On 20 Dec 2014  Viewed: 3,014
  • xml
  • xdocument
  • asp.net
  • c#

ASP.Net MVC multiple submit button use in different ways

Multiple submit button in ASP.Net MVC is the common and mostly asked question in interview. In this article we will try to see different ways to use the Multiple submit button in a form and what is the best way to use multiple submit button. What we are going to try: 1. HTML5 FormAction and FormMethod attribute in submit buttons 2. Multiple Submit Buttons With Action Selector Attribute 3.... By Ali Adravi   On 08 Oct 2017  Viewed: 2,941
  • asp.net
  • mvc

Readonly textbox postback issues and solutions

In many cases we need to use read only text box so user cannot edit the value but readonly textbox will lost its value after postback. Let’s say you have a read only text box to set date by using ajax calendar so after post back date will be lost, other case might be you are setting some value in design view of aspx page which will lost after post back. Suppose you have following HTML in your... By Ali Adravi   On 24 Apr 2013  Viewed: 2,905
  • asp.net

ASP.Net 4.5 new feature Model Binding

A nice feature with ASP.Net is the model binding, it reduced our code and effort to bind our well know controls like GridView, DataList, Repeater etc. So let’s see how we can bind our old controls in new and easy way. Let’s see how we bind the our grid before 4.5 1. We write the code to get data from database 2. Set the data source of control say GridView 3. Finally call the DataBind()... By Mike .Net   On 17 Jan 2013  Viewed: 2,679
  • asp.net

ASP.Net page life cycle events, orders and purpose

ASP.NET Page Life Cycle order and events Page life cycle is very important concept to understand while working with asp.net, what are the stages we can read the view state values and what is the last event where can write back our view state again. When to load the dynamic controls and when to check the values of dynamically added controls, It is impossible to work without knowing the basics of... By Hamden   On 24 Jan 2015  Viewed: 2,662
  • asp.net

Bind multiple value for hyperlink in gridview

When need to use a JavaScript function with multiple parameters and those parameter values need to be bind at the time of binding the gridview data then it really becomes complicated, say we have a function GetLatLong which calculates Latitude and Longitude by using city, state, Country and zip code, say our function is something like this function GetLatLong(var city, var state, var... By Ali Adravi   On 20 May 2013  Viewed: 2,303
  • asp.net
  • gridview
  • binding

Routing with asp.net web forms application

Microsoft .NET Framework 3.5 SP1 introduced a routing engine to the ASP.NET runtime. The routing engine can decouple the URL in an incoming HTTP request from the physical Web Form that responds to the request, allowing you to build friendly URLs for your Web applications. Let's start make our web application work with routing, first of all you need to do some changes in your global.asax file,... By Ali Adravi   On 05 Jan 2013  Viewed: 2,145
  • asp.net
  • routing

XmlDocument Vs XDocument and their usage

When there was XmlDocument why we need XDocument, is there any better feature available with XDocument, answer is yes, XDocument has a number of benefits, easy to create, easy to update, easy to search, ability to use LINQ to XML, cleaner object model etc. In this post we will see some examples and difference of code while using XmlDocument and XDocument; we will discuss some way to convert... By Ali Adravi   On 16 Mar 2013  Viewed: 2,087
  • xml
  • asp.net
  • c#

Cookies in asp.net with examples

We will discuss here, what are cookies, why we need cookies, what are the limitation of cookies, when we need to use cookies with example code in asp.net and many more. ***what are cookies:*** HTTP Cookie, Web Cookie, Browser Cookie, Session Cookie, etc. are some names of the cookies. Cookies are small text file sent by web server and saved by browser on client machine. We need cookies to... By Myghty   On 26 May 2013  Viewed: 2,034
  • cookies
  • asp.net

Range Validator in ASP.Net

How and when to use RangeValidator is a tricky question, can we use RangeValidator to validate a string or date, most of us say we can not use RangeValidator for string but we can, we will see How to use RangeValidator for string?, How to use MinimumValue and MaximumValue for type String? ASP.net provides easy to use control to validate a control value between the range. It can be used to... By Tigers   On 29 Dec 2012  Viewed: 1,754
  • asp.net
  • rangevalidator

Convert string to an enum type in .net

Sometime we need to convert string to an enum type, say I need to store my enum value into viewstate then we cannot store enum or any object to viewstate so converted that to string and store it, and on postback need to read the viewstate and convert to enum, so how to convert a string into enum? We will see this in this article. Let’s say our enum is like this: Public enum ReportType ... By Hamden   On 21 May 2013  Viewed: 1,283
  • enum
  • c#
  • asp.net
  • oops

Convert xml, json to class in asp.net c# by one click

Convert XML or JSON into a class by using visual studio is as easy as just copy and two clicks, never matter how big or how complicated is our XML or JSON. In this article we will create some dummy XML and json and will try to convert them into class without writing a single property manually. It does not create 100% correct data type but created all the properties for. Say we have an XML or... By Ali Adravi   On 20 Dec 2014  Viewed: 1,214
  • xml
  • json
  • c#
  • object
  • asp.net

Log error in a text file in ASP.Net

It’s good practice to log all the error into a file or database so in future you can check, how your application is working, and is there any issue which is not caught by Q.A. team. Really it's helpful to understand and caught the issues after deploying the application on production server. Create a method to log the error into a file: public void LogError(Exception ex, String... By Myghty   On 30 Dec 2012  Viewed: 1,143
  • asp.net
  • c#

Use XSLT to create menu from database

In some situations we need to create website menu from database, say our application have ability to create pages so that must also need to have a menu item to go to that page. So how to create menu with all those nice CSS and other settings, I think XSLT is best to use in these situations. Let’s see what we would need to create our menu 1. Procedure to get data from database in xml... By Hamden   On 16 Mar 2013  Viewed: 1,116
  • html
  • xml
  • asp.net

What is ASP.Net Web API, why & when to use

What is ASP.Net Web API, what is RESTFul service, What is the difference between WCF and Web API and when to use over other. These are the main points which we going to discuss in this starting article, then we will create our own Web API project and look each and every single type of methods like get, post, put, delete. We will also use the Entity Framework to get and post the data to SQL... By Ali Adravi   On 13 Jul 2017  Viewed: 1,063
  • web-api
  • wcf
  • asp.net
123