Tuesday, 4 February 2014

Hosting the MVC application using the IIS

IIS, to run the application instead of the built-in asp.net development server.




1. In the solution explorer, right click on the project and select "Properties"
2. Click on "Web" tab
3. Select "Use Local IIS Web Server" radio button
4. Notice that the Project Url is set to http://localhost/MVCDemo by default
5. Finally click on "Create Virtual Directory" button

Creating the first MVC application

Follow the steps as shown and create your hello world mvc application

1.
 Open visual studio
2. Click File > New Project
3. Select "Web" from "Installed Templates" section
4. Select ASP.NET MVC 4 Web Application(If dont have  MVC 4 means then ASP.NET MVC 3) 
5. Set Name="MVCDemo"
6. Click OK
7. Select "Empty" template. Select "Razor" as the ViewEngine. There are 2 built in view engines - Razor and ASPX. Razor is preferred by most mvc developers. 
8. At this point you should have an mvc application created.

Notice that in the solution explorer, you have several folders - Models, Views, Controllers etc. As the names
 suggest these folders are going to contain Models, Views, and Controllers. 

·         Model , which represents the underlying, logical structure of data in a software application and the high-level class associated with it. This object model does not contain any information about the user interface.
·         View , which is a collection of classes representing the elements in the user interface (all of the things the user can see and respond to on the screen, such as buttons, display boxes, and so forth)
·         Controller , which represents the classes connecting the model and the view, and is used to communicate between classes in the model and view.
Now let's add a controller to our project
1. Right Click on "Controllers" folder
2. Select Add > Controller
3. Set Controller Name = HomeController
4. Leave rest of the defaults and click "Add"
We should have HomeController.cs added to "Controllers" folder. 

At this point run the application by pressing CTRL+F5. Notice that you get an error as shown below.

The First type is as follows
 Right click on the Index() function and Click on "Add View"
Notice that, the view name in "Add View" dialog box matches the name of the controller action method.Select "Razor" as the view engine.Leave the rest of the defaults as is, and click "Add" button.

The Second type is as follows
The following is the function that is automatically added to HomeController class.

public ActionResult Index()
{
    return View();
}

Change the return type of Index() function from "ActionResult" to "string", and return string "Hello from MVC Application" instead of View().

public string Index()
{
    return "Hello from MVC Application";
}

Run the application and notice that, the string is rendered on the screen. When you run the application, by default it is using built-in asp.net development server. In the URL "Home" is the name of the controller and "Index" is the method within HomeController class.
 Finally your first hello world MVC application has been completed

Tuesday, 17 December 2013

Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack


Solved : Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack

Reason:
     The Response.End method ends the page execution and shifts the execution to the Application_EndRequest event in the application's event pipeline. The line of code that follows Response.End is not executed.This problem occurs in the Response.Redirect and Server.Transfer methods because both methods call Response.End internally.
Solution: 
For Response.Redirect
Response.Redirect ("nextpageURL.aspx", false);
For Server.Transfer
Use Server.Execute instead of Server.Transfer

Separate characters in a string using SPLIT and ARRAY

The SPLIT will separate the characters using a unique character or symbol like + , . @_ - etc. and store values in the ARRAY.

Example :

protected void buttonname_Click(object sender, EventArgs e)
{
string a = It-is-a-demo;

string[] b = a.split('-');  //It will split the characters after each of this special character underscore -

string split1 = b[0];  //It will be stored using the array
string split2 = b[1];  // is will be stored
string split3 = b[2];  // a will be stored
string split4 = b[3];  // demo will be stored

lbllaststring.Text = split4;  //demo will be displayed in the label
}

Saturday, 27 July 2013

How to Create the SQL Stored Procedure


Open the SQL server 2005 or 2008 and then create a database and the tables and add the fields as your requirement.Here in this example I use two fields.

ID  int
Name  Varchar(50)

Now Click the New query and the Type following Stored Procedure :

USE [DBNAME]

GO

CREATE procedure Sp_Tblname
@ID int=0,
@Name varchar(50)=null,
@Mode varchar(100)=null
as
begin

if @Mode='Insert'
Insert into Tblname(Name) values (@Name)
end

if @Mode='Update'
begin
update Tblname set Name=@Name where ID=@ID
end

if @Mode='Delete'
begin
Delete from Tblname where ID=@ID
end

if @Mode='Selectall'
begin
Select * from Tblname
end

end

This is the simple stored procedure created using sql.After completing it u can Execute it.
After this u can call these parameters and stored procedure as shown in this link http://sathyadotnet.blogspot.in/search/label/3-Tier%20Architecture.

Thursday, 25 July 2013

How To Back Up Complete BLOG and Template



Here the Entire BLOG can be back up through Google takeout(https://www.google.com/takeout/#custom) and also directly from your BLOG.First I tell you how to back up using Google takeout and then from the blog directly.

Back up Blog using Google TakeOut:

1, Login to https://www.google.com/takeout/#custom using your respective blog account.

2, After that Click Choose services and then in the Select service choose Blooger

3, Select the “Create Archive” button.
4, Once the progress bar reaches 100%,Click Download(It automatically compress the file and start downloading)

5,Thats it!!! YOUR BLOG BACK UP GETS OVER.

Back up Blog directly from your Blog:
1, Open your blog and then Sign In
2, Then go to Settings from Design or Dashboard.
3, Click the Other options from Settings tab.

4, Look at the Blog Tools: Import Blog - Export Blog - Delete Blog.
5, Hit on the Export Blog.

6, Now click Download Blog.

7, Save the .xml file in your hard disk.

Then If you wanna restore your blog from that previously saved copy then follow the above steps again. Just in the step 5 you have to Choose Import Blog. Then choose and upload the .xml file that you've saved in your hard disk...

Back up your Blog Template:
1, Open your blog and then Sign In
2, Then go to Template from Design or Dashboard.
3, Now Click Backup/Restore at the top right as shown
4, Then click the Download the template and save it in XML format.


If you want to Upload that saved file follow the same but at Step4 click the choose file and then click Upload.


Friday, 19 July 2013

ADD SMOOTH BACK TO TOP BUTTON FOR BLOGGER

If you have lot of contents in your blog pages, and if you want to make your blog to be easy to navigate for your readers, a back to top button will make it easy and perfect....

Step 1: Log on your blogger account and Go to, Dashboard > Template > Edit html.

Step 2: Find the following tag by using "Ctrl + F".

]]></b:skin> 


Step 3: Copy and Paste below code before the above tag.

#backtotop {
padding:5px;
position:fixed;
bottom: 5px;
right: 5px;
cursor:pointer;
}


Step 4: Find the </body> tag by using "Ctrl + F" and copy and paste below code before the </body> tag.

<a href="#" id="backtotop"><img src="Image Url" alt="back to top" /></a>

Step 5: Now select your free back to top button in the below list and copy and paste it’s Image URL in to the place of "Image Url" of above code.



 

1. Image Url : https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjgd9SBqUcL5aZc2asOck9bGTQUljlDnAThyphenhyphen5nuBvnEdK27kjZWD5V0K14SQovGVBazmqsQJlO1aLCLYNAKTHafDphcIUmkhhRETAqV3dao-DHP4kVv8MlTL6gdyqs_1rUc4B-anA4Jm5K6/s1600/new+back+to+top+button.png

back_to_top image 
2. Image Url : https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjUGGqzjbdtW9ZNaMhKHeomD4OPbIu-4aY83RqIyceGCiEyVvgSCRmq3TzVpaw8o89sKnLibU8vjm9wN1q14CFM_55ifuLfqosMpPeCh5yWelJa9gzCa_41UIAnh7PeYP-gV-jBmfhTD06g/s1600/back+to+top+button.png
back to top gadget
3. Image Url : https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhBj6mb4yAXdzo9_iqYWxTQmdHnL9XEr9AkukO4w5DmA691Qyy6fl9pNrBgE0TZfTOB2kgV1p0qat1MfKSqjz9J8r81Qyxl3FBys4jAdxHLn0fcFzDofcKO5N-7C3JSLO55iKoSDJhnXMGw/s1600/Back_to_top_image.png

back to top classic button
4. Image Url : https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEixFVpHm2sY0E9rB-eCKT99dJ9fLY77t_FtSzLYaov0zT_ayToftbSxg2PoCwSc1slO6RJHao_amGGdmyzwZsLz0nuRC_HDTU1Pq2t2grr5Y96GJTDcp9KP4MoJwuw6rC0_udu7IgAGs7Hj/s1600/back_to_top.png


back to top

5. Image Url : https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEii4hq1S7UVfZ1TCmqEczG9N7-vEF7Bliol20fHHPVz_iUN3TTzibiV_iMXhtfC3i5bDs-oyHITH29q361cLZ6zN-P-FG-9CJ7XIHucnMlkgGNmK8rXqoSqsOeNRDtrOZFWxDYTM4sIF-aG/s1600/back+to+top+icon.png



6. Image Url : https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg_JijpcKQdoUgfB2HYoLLLgdLWbkKU8w7Dm6tcgFfV88UeJpcr2SZ0yMGZHH8eNfaZdj20B_l7G5zcu2zrAwq4PdiQ-GNcYBafIM7oK9VxWO_HFqa1hzhNiU8bye4_7PfYN8To7moat3fC/s1600/back_to_top_button.png

 
7. Image Url : https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjXoMB4VH-h9x9HQQnVuNUeT36LGs1A39GIAKSgpLlF5Ijw_EB1oCvp_tqfvCbqAdIJkFWz7i9QdbWQbHGfv7R0Lti_R0MokwCcmRypqgyJh-uWUHKk8PQOBXfIwd4tARv7M4rQo97Xiyaf/s1600/back+to+top.png

back to top button
8. Image Url : https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEioOyBLD_XntPDNryYCA_z3WFKl4zjtKCP_aUtHoXk5jOn46Ufg1MNMS1KnLC6af4toOfyo9ctmChC28hoO2tvLF6yBinnLHxN8Ae4jsfzh3XYKH3t7fur9xv5MCpN6NMQ00dEf7Pek2cqJ/s1600/back+to+top.png



Step 6: Find the <head> tag by using "Ctrl + F" and copy and paste below code after the <head> tag and save template..

<!-- start back to top -->
&lt;script src='http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js'
type='text/javascript'&gt;&lt;/script&gt;
&lt;script language=&quot;javascript&quot;&gt;
$(window).ready(function(){
$('#backtotop').click(function(e){
e.preventDefault();
$('html, body').animate({scrollTop:0}, 'slow');
});
});
&lt;/script&gt;
<!-- end back to top -->

back to top