Hi Friends,
Recently i went to one company for interview. There interviewr ask me one viewstate question
There were Scenarion where we will store one viewstate value on page load and display on button click.
Interviewer asked if i will run this page and after i will click page source and change the viewstate value what heppend....page will work properly??
Ans:- Page will be corrupt.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication2.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="lblName" runat="server"></asp:Label>
<asp:button ID="btnClick" runat="server" Text="Submit" OnClick="btnClick_Click" />
</div>
</form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication2
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
ViewState["Name"] = "Puneet";
}
protected void btnClick_Click(object sender, EventArgs e)
{
lblName.Text = ViewState["Name"].ToString();
}
}
}
Step-1: Run the page and right click on page
Step2:- Change View State Value
Add AAAAAA in last in viewstate value
Interviewer asked if i will run this page and after i will click page source and change the viewstate value what heppend....page will work properly??
Ans:- Page will be corrupt.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication2.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="lblName" runat="server"></asp:Label>
<asp:button ID="btnClick" runat="server" Text="Submit" OnClick="btnClick_Click" />
</div>
</form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication2
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
ViewState["Name"] = "Puneet";
}
protected void btnClick_Click(object sender, EventArgs e)
{
lblName.Text = ViewState["Name"].ToString();
}
}
}
Step-1: Run the page and right click on page
Step2:- Change View State Value
Add AAAAAA in last in viewstate value
No comments:
Post a Comment