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

How to get values from Web.Config file which is defined in AppSettings section as below? <appSettings> <add key="MaxSearchCount" value="100" /> </appSettings>

With the help off AppSettings method of ConfigurationManager class,we can get value from Web.Config file as:-

string max_search_count = Convert.ToString(System.Configuration.ConfigurationManager.AppSettings["MaxSearchCount"]);

max_search_count will have 100.
How to remove both leading and trailing spaces from string?

Use Trim() method of Dot Net.we can remove any start and end space of string value.

For Example:-

string str = " Vishal ";
str = str.Trim();

Output will be:- "Vishal"
How to Disable Auto-Fill option for Textbox only?

Set autocomplete = "off" for particular Textbox.

For Example:-
If want to disable Autocomplete feature for a particular Textbox,then we will write as:-

<asp:TextBox runat = "server" ID ="txt_payment" autocomplete = "off"></asp:TextBox>


If we have enabled Auto-fill features in our browser, then each and every time when we enter any value in TextBox,then a Dropdown list appears with values in
that TextBox.
How to disable Auto-fill at page-level?

We can turn off auto-fill at page-level by setting autocomplete attribute value to off as shown below:-

<form id="frm" method="post" runat="server" autocomplete = "off">

</form>

Which directive is added to the page while creating Web UserControl?

NOTE: This is objective type question, Please click question title for correct answer.
How to retrieve value from Cookie?

With the help of Request.Cookies method,we can retrieve any Cookie' value.

For example:-

string employee_info = Request.Cookies["EmployeeMaster"].Value;


Here,EmployeeMaster is a Key.
How do we create a Cookie in Asp.Net?

With the help of Response.Cookies method,we can create Cookie

For Example:-

Response.Cookies["EmployeeMaster"].Value = "Vishal";


Here,Vishal will be stored in Employeemaster key.
How to disable Particular Textbox control ViewState?

With the help of EnableViewState property,we can Enable or Disable Particular Textbox control. We have to set EnableViewState property to True/False.

For Example:-

<asp:TextBox ID="txt_requirion" runat="server" EnableViewState="false"></asp:TextBox>

What is the default value of EnableViewState property.

By-default EnableViewState property is True for any control.

As we know that,Viewstate is used for retaining values among multiple postbacks.To work with such things,we have EnableViewState property in Asp.Net,which we have to set to True/False
in control-level,page-level and application-level.

<asp:TextBox ID="TextBox1" runat="server" EnableViewState ="true/false"></asp:TextBox>

How can we control viewstate for all control at page-level?

We can set EnableViewState property to True or False at page level as:-

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" EnableViewState="false"  %>

How can we control ViewState globally?

In the Pages section inside web.config file,we can set EnableViewState property to True/False,which will be applied in all the pages in an application.

For Example:-

To enable/disable a ViewState,in web.config file write:-

<configuration>


<system.web>

<pages enableViewState="false">

</system.web>

</configuration>

How to load Themes dynamically?

We can load Theme dynamically in Asp.Net in Page-load as

protected void Page_Load()
{
Page.Theme = "Green";
}

Where Green is my Theme name.
How to change Page Title Dynamically?

With the help of Page.Title property,we can change Title Dynamically.

protected void Page_Load(object sender, EventArgs e)

{
if (Session["Page_From"] == "Recruitment")
{
Page.Title = "Recruitment Console";
}
else
{
Page.Title = "Referrel Console";
}
}

How to show only horizontal scroll bar only?

With the help of Overflow CSS Property,we can show Horizontal scroll bars as there is X and Y direction.
X means Horizontal and Y means Vertical direction.

For Example:-

.horizonatal_scroll_bar

{
overflow-x:auto;
}

How to hide Vertical scroll bar only.

With the help of Overflow CSS Property,we can hide Vertical scroll bars as there is X and Y direction.
X means Horizontal and Y means Vertical direction.

For Example:-

.hide_vertical_scroll_bar

{
overflow-y:hidden;
}

How to wrap long text into multiple line?

word-wrap CSS property is used for breaking long texts into multiple lines.

For Example:-

.break_word

{
word-wrap:break-word;
}


Now,you have to apply above CSS property in TextBox control.
How to set Default focus on Button.

defaultbutton property is used for setting focus on Button.

defaultbutton works as an Enter key.
When user press enter key from keyboard,then Button event automatically fired.

For Example:-

<form id="form1" runat="server" defaultbutton="btnSubmit">

<div>
<asp:Button ID="btnSubmit" runat="server" OnClick="btnSubmit_Click" Text="Submit"/>
</div>
</form>

How to change Button color as transparent dynamically?

With the help of Transparent property of Color,we can change Button background color.

btn.BackColor = Color.Transparent;

Color comes under System.Drawing namespaces.
How to refresh Page automatically in a interval of 15 seconds?

Automatic web page refresh can be implemented in an ASP.NET web-page by adding some HTML code in the header section.

We can simply add following line of code in the Header section to enable auto refresh in an ASP.NET web page.

<meta http-equiv="refresh" content="15">


Where 15 refers to the number of seconds it will take before refreshing the page.
How to get the Host Name of a computer?

We use GetHostName() method of System.Net.Dns class to get the Host name.

For Example:-
string strHostName = System.Net.Dns.GetHostName();


We can also import System.Net namespace.
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