ASP.NET Interview Questions and Answers (1544) - Page 70

How to disable Mouse right click on web page?

Simply give oncontextmenu event of Body tag to false will disable Mouse right click on entire web page as:-
<body oncontextmenu = "return false;">  

</body>

How to enforce Maximum character length Validation or how to allow maximum of 5 letters?

We will use Asp.net RegularExpressionValidator control to achieve this task:-

Refer below code:-
<asp:TextBox Id = "txt_employee_code" runat = "server"></asp:TextBox>


<asp:RegularExpressionValidator Display = "Dynamic" ControlToValidate = "txt_employee_code" Id = "reg_ex_employee_code" ValidationExpression = "^[\s\S]{0,5}$" runat = "server" ErrorMessage = "Maximum of 5 letters allowed"></asp:RegularExpressionValidator>


It will allow only 5 letters after that it will give error mmessage as Maximum of 5 letters allowed
How to enforce Minimum character length Validation or how to allow Minimum of 4 letters?

We will use Asp.net RegularExpressionValidator control to achieve this task:-

Refer below code:-
<asp:TextBox Id = "txt_employee_code" runat = "server"></asp:TextBox>


<asp:RegularExpressionValidator Display = "Dynamic" ControlToValidate = "txt_employee_code" Id = "reg_ex_employee_code" ValidationExpression = "^[\s\S]{4,}$" runat = "server" ErrorMessage = "Minimum of 4 letters allowed only"></asp:RegularExpressionValidator>

How to allow Minimum of 5 and Maximum of 7 letters in a Textbox?

We will write below code:-
<asp:TextBox Id = "txt_employee_code" runat = "server"></asp:TextBox>


<asp:RegularExpressionValidator Display = "Dynamic" ControlToValidate = "txt_employee_code" Id = "reg_ex_employee_code" ValidationExpression = "^[\s\S]{5,7}$" runat = "server" ErrorMessage =

"Minimum of 5 and Maximum of 7 letters allowed only"></asp:RegularExpressionValidator>

How to disable Enter key pressed inside TextBox to avoid submission or postback in Asp.Net?

In textbox definition,we have to write below code on onkeydown event as:-
<asp:TextBox ID="txt_emp_first_name" runat="server" onkeydown = "return(event.keyCode!=13);"></asp:TextBox>

Here,13 is keyboard Enter button key code.
When enter key is pressed the above condition is false hence false is returned therefore the postback will be disabled.
How to disable Enter key pressed inside TextBox to avoid submission or postback through code behind?

Visual Studio gives us a warning message when we add onkeydown event.But it's just a warning so we can ignore.So to avoid this warning,we can also disable submission from code behind as:-
txt_emp_first_name.Attributes.Add("onkeydown","return (event.keyCode!=13);");

//OR
txt_emp_first_name.Attributes.Add("onkeydown","prevent_submission();");

Abobe return code should be written inside prevent_submission() js function.
How to disable the Enter key pressed form post-back for all page controls?

Simply add below code in the body tag as:
<body onkeydown = "return (event.keyCode!=13);">

Then it will be disabled for all controls on the page.
How to get information from a form which is submitted using the post method?

NOTE: This is objective type question, Please click question title for correct answer.
How to get information from a form that is submitted using the GET method?

NOTE: This is objective type question, Please click question title for correct answer.
Which Process is used for Maintaining State Server Session in Asp.Net web page?

NOTE: This is objective type question, Please click question title for correct answer.
We have defined one page_load event in aspx page and the same is defined in code behind page then which event will fire first?

NOTE: This is objective type question, Please click question title for correct answer.
In order to prevent a browser from caching a page which of the statement will you write?

NOTE: This is objective type question, Please click question title for correct answer.
By default,Asp.Net stores SessionIDs in which mechanism?

NOTE: This is objective type question, Please click question title for correct answer.
In which location,VS.NET stores Web application projects?

Web application projects create a virtual folder for each project where all the files of the projects are stored. The virtual folder can be viewed in IIS and property of that folder determines where the files are physically stored.
How to set the compatibility mode of Internet Explorer dynamically?

Just add below Meta tag directly below inside Head Tag as:-
<meta http-equiv = "X-UA-Compatible" content = "IE=9">/

Note:- Above code will change compatibility mode for IE9 version.
How to set a various number of compatibility modes in Internet Explorer?

If we want to set a number of compatibility modes,then we have to specify the range in ascending order as comma-separated list.Then IE will choose the highest of the specified modes that it can support.
For Example:-
<meta http-equiv="X-UA-Compatible" content="IE=7,8,9">

How to set default compatibility modes in config file?

If we are running a .NET site, then we can specify the default Compatilbility View for our entire site in the CustomHeaders section of our Web.config file as follows:-
<customHeaders>

<clear />
<add name="X-UA-Compatible" value="IE=9" />
</customHeaders>

if we have access to IIS,then we can specify the Compatibility View meta tag using a custom HTTP response header.
Which process is used to execute Web application from Visual Studio environment?

WebDev.WebServer.Exe is the process which is used to run Web application from Visual Studio.
What are the disadvantages of setting cookieless to true?

Setting Cookieless = true implies some restrictions,mainly:-
1). We can not use absolute link in our pages.
2). We have to perform additional steps to switch between http and https pages in our application.
3). If our customer sends a link to a friend,the URL will contain the session ID and both users could be using the same session ID at the same time.
Which method of page is used to load user control dynamically?

NOTE: This is objective type question, Please click question title for correct answer.
Found this useful, bookmark this page to the blog or social networking websites. Page copy protected against web site content infringement by Copyscape

 Interview Questions and Answers Categories