Friday, May 30, 2014
CROSS Page Posting in ASP.NET
Postback and Cross Page Posting
If(Page.IsPostBack==true)
Ispostback->
When the page is loaded for the first time it is false, when the page is loaded again then it is true.
Example
If (Ispostback) ->
If true then it goes inside that loop
If (! ispostback) ->
If false then it goes inside that loop. We write this line in page load in most of the application.
Cross Page PostBack is which is used to submit one Page(Default.aspx) controls to another page(Default2.aspx) and access Default.aspx control values in Another Page(Default2.aspx)
Example
Cross page posting is submitting the form to a different page. This is usually required when you are creating a multi-page form to collect information from the user on each page. When moving from the source to the target page, the values of controls in the source page can be accessed in the target page.
Design the Form as
Default2.aspx
Default2.aspx.cs
Go to Default3.aspx
Default3.aspx.cs
Difference between Server. Transfer and Cross Page Posting
In ‘Server.Transfer’, the URL doesn't change whereas in cross page posting, the form is submitted to a different page, thereby changing the url.
The Server.Transfer method is a server-based operation whereas cross-page postback is a client-based transfer.
By using Master Page
ContentPlaceHolder pageContent =
(ContentPlaceHolder)
(Page.PreviousPage.Form.FindControl ("Content1"));
TextBox1.Text = pageContent.FindControl("button1");
To avoid casting the control type, you can also access the previous page data(Default2.aspx) by creating public properties that expose the data that you need to access.
In Default2.aspx
public String BTarget
{
get
{
return button1.Text;
}
}
In the ‘Default3.aspx’, access the value of the Button using the exposed property
Label1.Text = PreviousPage.BTarget;
MVC Basic Example
File->New Project->Select the template
ASP.NET MVC4 Web Application
Select the type of Template
And Click On OK Button
Now I want to create a page without using Master Page.
Master page is located at the following location
By default one master page is created, so now I want to create a page without using that default master page or any other master page which is created by you.
Now go to controller
And right click on Controller and Select Add Controller and Give the name as Default Controller.
And Click on Add Button
By default one Method is created for Every Controller.
So every controller by default has this Method Index (). So whenever we run this Controller by Default Index Method will Gets Executed. So now I want to create my own method and run that method by Default.
So now I have created my Own Method that Is Default Index (). So now the controller is ready. So we have to create a View for this Controller.
So go to Controller and Right click on Selected Method Name i.e. (Default Index)
And select Add View
And Click on Add Button
By default the same Name is used for View Also. (I.e. Default Index)
DefaultIndex.cs.html
So now the View is created without using the Master Page.
Now I want to Run, the View. So Go to RouteConfig
And set the Controller Name and the Method Name, so that when we run the Application by Default this View is displayed (this is similar to Set as Start Page in aspx)
Now Run the Application and See the output
Thursday, May 29, 2014
MVC KENDO GRID WORKING
MVC Kendo Grid Example
1St Method
First Go to Master Page.
And add the following line of Code. Now when I click on Employee the Details should be displayed to me.
Now I need to create an Employee Controller.Before That I would like to
1 Create a Folder with View Models.
2 create a class with name “EmployeeViewModel” to add gets and sets properties.
Go to EmployeeViewModel.cs and write the following lines of Code.
public class EmployeeViewModel
{
public int Employeeno { get; set; }
public string EmployeeName { get; set; }
public string EmployeeAddress { get; set; }
public List<EmployeeViewModel> lstEmployees { get; set; }
}
Add the Reference of Kendo
And then go to Web.Config and add namespace for Kendo ( in both the web.config files)
1 which is inside View Folder
2 which is outside
To Apply Styles
Go to Content Folder, all the styles related to Kendo need to be paste here.
All the scripts files related to Kendo need to be in Scripts Folder
Then go to master page (layout.cs.html) under View Folder and add the following styles and js files related to Kendo.
Then go to controller folder , and select
And Click On Add button.
Write the following Method in Employee Controller as shown above.
Create a Model Class with Name Employee.cs and write the following code as shown.
So go to Controller and Right click on Selected Method Name i.e. (Employee Details)
And Click on Add Button.
Write the following code
@model MvcApplication3.ViewModels.EmployeeViewModel
@{
ViewBag.Title = "EmployeeDetails";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>EmployeeDetails</h2>
@(Html.Kendo().Grid(Model.lstEmployees)
.Name("grdReports")
.Columns(columns =>
{
columns.Bound(c => c.Employeeno).Width(140);
columns.Bound(c => c.EmployeeName).Width(90);
columns.Bound(c => c.EmployeeAddress).Width(90);
})
// .BindTo(Model.GetReportDetails())
.Sortable()
.Pageable(pageable => pageable
.Refresh(true)
.PageSizes(false)
.ButtonCount(2))
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(5)
.ServerOperation(false)
)
)
And Run the application
Click on Employee Tab
JAVASCRIPT BASIC EXAMPLES FOR BEGINNERS(Performing Add, Sub, Multiply,Divide.)
Performing Add, Sub, Multiply,Divide.
<HEAD><CENTER> </center></HEAD>
<SCRIPT LANGUAGE="JAVASCRIPT">
function fadd_click()
{
accept();
document.f1.c.value=eval(x)+eval(y);
}
function fdiff_click()
{
accept();
document.f1.c.value=eval(x)-eval(y);
}
function fmult_click()
{
accept();
document.f1.c.value=eval(x)*eval(y);
}
function fQuo()
{
accept();
document.f1.c.value=eval(x)/eval(y);
}
function accept()
{
x=window.prompt("enter the value");
y=window.prompt("enter the value");
}
</SCRIPT>
<BODY>
<FORM NAME=f1>
<CENTER>
<INPUT TYPE=BUTTON NAME=B1 VALUE=" + " onClick="fadd_click()">   
<INPUT TYPE=BUTTON NAME=B4 VALUE=" - " onClick="fdiff_click()">   
<INPUT TYPE=BUTTON NAME=B2 VALUE=" * " onClick="fmult_click()">   
<INPUT TYPE=BUTTON NAME=B3 VALUE="/" onClick="fQuo()">   
<INPUT TYPE = TEXT NAME="c">   
</center>
</FORM>
</BODY>
</HTML>
<HEAD><CENTER> </center></HEAD>
<SCRIPT LANGUAGE="JAVASCRIPT">
function fadd_click()
{
accept();
document.f1.c.value=eval(x)+eval(y);
}
function fdiff_click()
{
accept();
document.f1.c.value=eval(x)-eval(y);
}
function fmult_click()
{
accept();
document.f1.c.value=eval(x)*eval(y);
}
function fQuo()
{
accept();
document.f1.c.value=eval(x)/eval(y);
}
function accept()
{
x=window.prompt("enter the value");
y=window.prompt("enter the value");
}
</SCRIPT>
<BODY>
<FORM NAME=f1>
<CENTER>
<INPUT TYPE=BUTTON NAME=B1 VALUE=" + " onClick="fadd_click()">   
<INPUT TYPE=BUTTON NAME=B4 VALUE=" - " onClick="fdiff_click()">   
<INPUT TYPE=BUTTON NAME=B2 VALUE=" * " onClick="fmult_click()">   
<INPUT TYPE=BUTTON NAME=B3 VALUE="/" onClick="fQuo()">   
<INPUT TYPE = TEXT NAME="c">   
</center>
</FORM>
</BODY>
</HTML>
MVC CURD OPERATIONS WITH KENDO GRID
First Go to Master Page.
And add the following line of Code. Now when I click on Employee the Details should be displayed to me.
Now I need to create an Employee Controller. Before That I would like to
1 Create a Folder with View Models.
2 create a class with name “EmployeeViewModel” to add gets and sets properties.
Go to EmployeeViewModel.cs and write the following lines of Code.
public class EmployeeViewModel
{
public int Employeeno { get; set; }
public string EmployeeName { get; set; }
public string EmployeeAddress { get; set;}
public List<EmployeeViewModel> lstEmployees { get; set; }
}
Add the Reference of Kendo
And then go to Web.Config and add namespace for Kendo ( in both the web.config files)
1 which is inside View Folder
2 which is outside
To Apply Styles
Go to Content Folder, all the styles related to Kendo need to be paste here.
All the scripts files related to Kendo need to be in Scripts Folder
Then go to master page (layout.cs.html) under View Folder and add the following styles and js files related to Kendo.
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
<link href="@Url.Content("~/Content/Kendo/kendo.common.min.css")" rel="stylesheet"/>
<link href="@Url.Content("~/Content/Kendo/kendo.default.min.css")" rel="stylesheet"/>
<script src="@Url.Content("~/Scripts/jquery-1.7.1.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/Kendo/jquery.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/Kendo/kendo.all.min.js")" type="text/javascript"></script>
<scriptsrc="@Url.Content("~/Scripts/Kendo/kendo.aspnetmvc.min.js")" type="text/javascript"></script>
And comment the following lines of code below in master page.
@* @Scripts.Render("~/bundles/jquery")
@RenderSection("scripts", required: false)*@
Then go to Model and Create a model with a name Employee.cs
Add-> new item
And write the following line of code in Employee.cs as below
Then go to controller folder , and select
And Click On Add button.
So go to Controller and Right click on Selected Method Name i.e. (EmployeeGrid)
And select Add view
And write the following code in View
Run the application and see the output.
Subscribe to:
Posts (Atom)
Kubernetes
Prerequisites We assume anyone who wants to understand Kubernetes should have an understating of how the Docker works, how the Docker images...
-
Super aggregates: Are used to calculate aggregates of aggregates There are two super aggregates functions Roll Up Cube When there is a singl...
-
SOLID principles allows object oriented programming implementation in an efficient better way into project development S-->Single R...
-
With this example you can create pdf and print pdf. If You are using ASP.NET MVC , PDF can be created by using Rotativa Rotativa is a ...