What is the difference between client side script and by J4qpW1c7

VIEWS: 0 PAGES: 22

									                                                   ASP

What is Querystring collection?
This collection stores any values that are provided in the URL. This can be generated by three methods:
• By clicking on an anchor tag
• By sending a form to the server by the GET method
• Through user-typed HTTP address

What are the ASP Scripting Objects?
The Dictionary object, the FileSystemObject object, TextStream object.

What is the difference between client-side script and server-side script?
Scripts executed only by the browser without contacting the server is called client-side script. It is
browser dependent. The scripting code is visible to the user and hence not secure. Scripts executed by the
web server and processed by the server is called server-side script.
Explain the POST & GET Method or Explain the difference between them.
POST METHOD:
The POST method generates a FORM collection, which is sent as a HTTP request body. All the values
typed in the form will be stored in the FORM collection.
GET METHOD:
The GET method sends information by appending it to the URL (with a question mark) and stored as A
Querystring collection. The Querystring collection is passed to the server as name/value pair.
The length of the URL should be less than 255 characters.
What are Scripting Objects?
Objects that can enhance the application are known as the Scripting Objects.

What is the Order of precedence for LOGICAL Operators.
NOT, AND, OR, XOR, EQV, IMP
What are LOCAL and GLOBAL variables?
Local variables lifetime ends when the Procedure ends. Global variables lifetime begins at the start of the
script and ends at the end of the script and it can be used by any procedure within the script. Declaring a
variable by using the keyword PRIVATE makes the variable global within the script, but if declared using
PUBLIC, then all scripts can refer the variable.
What is Server-Side includes?
It provides extra information by which it makes the site easier to manage. It can include text files using
the #include statement, retrieve the size and last modification date of a file, defines how variables and
error messages are displayed and inserts the values of HTTP variables in the page sent back to the
browser.
What is a Scripting Language?
It permits to create more interactive Web Pages. Validation, formatting of web pages can be done.
VBScript, JavaScript are some examples.
What is an .ASP file?
It is a Text File that contains the combination of the following:
• Text
• HTML tags
• Script Commands
Naming constraints for a variable.
It can be up to 255 characters Must start with an alphabet Must not contain an embedded period or full-
stop
What is a TextStream object?
It allows you to access(read/write) the contents of text files stored on the web server.
What are the special sub-types in VBScript?
EMPTY: has no value
NULL: Value does not exist (conjunction with database)
OBJECT:
What is the difference between Cookies collection and Form/Querystring collection?
Cookie collection does not have the Count property.
Cookies can have multiple values for the same cookie name but each value can be referred using a key
whereas in a Form/Querystring cookie each value has to be referred using an index value.
What is Server Object?
Controls the ASP execution environment. It can set the amount of time script can run before an error
occurs. Converts a virtual path to a physical path on the server. Takes
a user supplied string and encode it into proper format for a URL string.
What is Collection?
Collection is a set of name/value pairs where the information supplied by the client is stored.
How will you delete a Cookie?
By setting its Expires property to any date prior to today Response.Cookies("cookie name").Expires =
Date – 1.
What is Application-scope?
Application-scope means that variables (and objects) can be accessed from any ASP pages that is part of
the
application.
What is Extranet?
An area of a web site available only to a set of registered visitors.
When is the Session_OnStart event fired?
A. Upon every request from an application by a client for an .asp document.
B. Upon the first request from an application by a client for any file in the application.
C. Upon the first request for an .asp document from an application by a client.
D. Upon the first request for the global.asa file, in which the event handler is located.
E. Upon the first request for an. html or .asp document from an application by client

<%
strName="John Smith"
%>
Referring to the above, if you want to pass the contents of the strName variable in a hyperlink,
which line of code would you use?
A. This cannot be done. The anchor is on the client and the
variable is on the server.
B. href="Encode.asp?name=<%=Server.URLPathEncode(strName)%>">click here</a>
C. <a href="Encode.asp?name=<%=strName%>">click here</a>
D. <a href="Encode.asp?name=<%=Server.HTMLEncode(strName)%>">click here</a>
E. <a href="Encode.asp?name=<%=Server.URLEncode(strName)%>">click here</a> (Answer)



<% varType = rsTest("field1").type %>
In the database table, if the datatype for field1 (shown above) is Number, what is the value of
varType?
    A. The field value.
        B. A string description. (Answer)
        C. The field name.
        D. NULL.
        E. An enumerator.
        How are sessions maintained?
    B. A. The browser sends a cookie to the server with each request. (Answer)
        B. The browser sends a Querystring variable to the server with each request.
        C. The browser sends a hidden Form variable to the server with each request.
        D. The browser sends a long variable to the server in the BODY of each request.
        E. None of the above.
    C.
    D. Using VBScript, which of the following Scripting Object(s) is NOT available from
        scrrun.dll?
E. A. TextStream
   B. Dictionary Object
   C. Err Object
   D. FileSystemObject
   E. All are available from scrrun.dll. (Answer)
Which will NOT set the scope of an Active Server Component?
A. Setting the [component name].scope property. (Answer)
   B. Using the Server.CreateObject method.
   C. Placing it in the Session or Application OnStart event handler.
   D. Instantiating the component in the global.asa file.
   E. Using the <OBJECT> tag.
   ClientCertificate is a collection of
       A. Server
            B. Response
            C. Request (Answer)
            D. ObjectContext

        IsClientConnected is a property of
        A. Server
            B. Response (Answer)
            C. Request
            D. Session
        What should be used in order to determine if the cookie "FavoriteFlavors" in the
        request object contains more than one entry?
        A. Request.Cookies("FavoriteFlavors").HasItems
            B. Request.Cookies("FavoriteFlavors").Collection.Count
            C. Request.Cookies("FavoriteFlavors").Dictionary
            D. Request.Cookies("FavoriteFlavors").HasKeys
            E. Request.Cookies("FavoriteFlavors").Count
        B.
        C.
        D.
        E.
        F. <%@ Language=VBScript %>
            <%If false then>
            <!-- #INCLUDE FILE="FunctionOne.inc"-->
            <%Else>
            <!-- #INCLUDE FILE="FunctionTwo.inc"-->
            <%End If>
            What would the above code load?
        G. A. Only the FunctionTwo.inc file into the ASP page. (Answer)
            B. Both files, since Server Side Includes are processed before ASP interpreting.
            C. Only the FunctionOne.inc file into the ASP page.
            D. Neither file, since Server Side Includes are processed before ASP interpreting.
            E. Neither file, since the #INCLUDE statements are commented out.
        <%
        Set Application("Thing") =
        Server.CreateObject("THINGDOER.thingy")
        %>
        The above code appears in the global.asa file. What would it accomplish?
        A. It would create a "Thing" object and place it in Contents Collection of the Application
            object.
            B. It would create a "Thing" object and place it in StaticObjects Collection of the
            Application object.
            C. It would create a "Thing" object and place it in the Application.Buffer Collection Of
            the Application object.
    D. It would create an application-level variable named "Thing" with the value of the
    object property "THINGDOER.thingy". (Answer)
    E. It would fail to create a "Thing" object because the code requires the Application.Lock
    and Application.Unlock methods.

<% Response.Redirect("http://www.sql.com") %>
What does the above code accomplish?
A. It sends the browser the line of sample code, and the browser executes it.
   B. It sends the response to "http://www.matsystems.com" instead of to the Requesting
   browser.
   C. It sends a redirection header back to the browser, and the browser then requests the
   new target document. (Answer)
   D. The redirection occurs on the server-side, and the first response the browser gets is the
   head and body of the new target document.
   E. It causes the server to send a request to the target URL and passes the response to the
   requesting browser.
   <input type=radio name=rbSex value="M">Male
   <Input type=radio name=rbSex value="F">Female
   Referring to the above, which line of code would retrieve the selected radio button
   value?
B. A. For cnt=0 to rbSex.count - 1
   If rbSex(cnt).value = selected Then
   strSex = rbSex(cnt).value
   exit for
   End If
   Next
   B. strSex = Request("rbSex").selected.value
   C. strSex = Request("rbSex") (Answer)
   D. strSex = Request.rbSex.value
   E. For Each value in rbSex
   If rbSex.selected = true
   strSex = value
   exit for
   Next
C. What happens when a client submits a form which changes the value of an
   Application variable?
D. A. Client actions cannot change Application variables.
   B. The change is not visible to any client until the application is stopped and started.
   C. The change is only visible to future requests made by that client during their current
   session.
   D. The change is visible to all clients, but only after they complete their current sessions
   and begin a new session.
   E. The change is visible to all clients immediately after the form is processed by the
   server. (Answer)
E. Following is the code Server.MapPath (".") consider the path is
   C:InetpubWWWRootMATDefault.asp. What will be the output
F. A. C:InetPUb
   B. C:InetPUbWWWroot
   C. C:InetPUbwwwrootMAT
   D. Error
G. What is the program ID (ProgID) for ActiveX Data Objects in 2-tier and 3-tier
   database applications?
H. A. ADO
   B. RDODB
   C. ADODB (Answer)
     D. RDS
     E. OLEDB
I.   <SCRIPT LANGUAGE="VBScript" RUNAT=Server>
     a=1
     </SCRIPT>
     <SCRIPT LANGUAGE="VBScript">
     a=2
     </SCRIPT>
     <%
     Response.Write a
     %>
     In the sample code shown above, what will be written to the screen?
J.   A. 1
     B. 2
     C. 1, 2
     D. 1&2
     E. Nothing. (Answer)
K.   <% iPos = Instr("Hello World","r") %>
     Referring to the above, what is the value of iPos?
L.   A. 0
     B. 1
     C. 2
     D. 8
     E. 9 (Answer)
M.   Which-code sample will report whether the client’s browser supports cookies?
N.   A. <% var objFSO = Server.CreateObject("Scripting.FileSystemObject") Response.Write
     objFSO.cookiesSupported %>
     B. You can only use JavaScript for this.
     C. <% var objFSO = Server.CreateObject("Scripting.FileSystemObject") Response.Write
     objFSO.cookies %>
     D. <% var objBrowser = Server.CreateObject("MSWC.BrowserType") Response.Write
     objBrowser.cookies %> (Answer)
     E. <% var objBrowser = Server.CreateObject("MSWC.BrowserType") Response.Write
     objBrowser.cookiesSupported %>
O.   What is ClientCertificate collection?
P.   A ClientCertificate is an encrypted number that is stored in a file on the user’s computer.
     This stores details of any security certificates included with the request.
Q.   What are the advantages of Cookies over Session Object?
R.   1) It informs each page what session the request belongs to when a user accesses during a
     session. 2) It retrieves all the session information stored on the server. 3) Cookies can
     persist for a much longer period of time than session that has a timeout value usually of
     20 minutes and hence can store information even when a user is off the site.
S.   What is the order of execution for an ASP application?
T.   1) Global.asa
     2) Server-side Includes
     3) Jscript scripts tagged within <SCRIPT> tags
     4) HTML together with scripts tagged within <% … %> delimiters
     5) VBScripts tagged within <SCRIPT> tags
U.   What are the types of HTML?
V.   • Static HTML – Browser uses HTTP to request HTML file from the Web Server
     • Dynamic HTML – Browser uses HTTP to request an executable application rather than
     a Static HTML file
W.   What are the properties of Session Object?
X.   • SessionID – returns the session identification number for each user.
     • Timeout – sets the timeout period assigned to the Session object for any application, in
     minutes.
                  • CodePage – determines the code page that will be used to display content.
                  • LCID – a locale identifier, which determines time zone and language, rules for the
                  system.
            Y. What are the advantages of using ASP?
            Z. • Minimizes network traffic by limiting the need for the browser and server to talk to
                  each other
                  • Makes for quicker loading time since HTML pages are only downloaded
                  • Allows to run programs in languages that are not supported by the browser
                  • Can provide the client with data that does not reside on the client’s machine
                  • Provides improved security measures since the script cannot be viewed by the browser
            AA.            What are the methods in Application Object?
            BB. Lock – prevents clients from modifying the variables stored in the Application object.
                  • Unlock – removes the lock from variables stored in the Application object.
            CC. What are the methods by which output stream is controlled?
            DD.            Flush – sends previous buffered output to the client immediately, but continues
                  processing the script.
                  • Clear – erases any already-buffered HTML.
                  • End – causes the server to stop processing the script.
                  What are the properties used to control the expiration of the page?
            • Expires – specifies the number of minutes before a page cached on a browser expires.
            • ExpiresAbsolute – sets the date and time at which a page cached on a browser expires.
            What are the collections of Session Object?
            Contents collection – contains all the variables established for a session without using the
            <OBJECT>
            tag.
            • Static collection – contains all the objects created with the <OBJECT> tag within session
            scope.
            Name some of the ASP components?
            ontent Linker component – a technique to direct users through a set of pages on a web site by
            creating
            a list of URLs and description of the next and previous pages.
            • Browser Capabilities component – allows to customize the page to the ability of the browser
            viewing it.
            • Database Access component – allows to access data from the database
            What are the tasks performed by <FORM> tags?
            <FORM> tags provides space for the user to input values
            • the form has a button to submit information back to the server
            • It transfers control to another ASP page
            • It carries the information in the fields to another ASP page
            What are the tags necessary to be present within the <FORM> tag?
            <INPUT> tag: Provides input spaces (text boxes, combo boxes, radio button, etc.) on a form
            called fields. It has three attributes TYPE, NAME and VALUE. TYPE provides the
            characteristics of the field and the NAME specifies a name to the field by which it can be
            referred.




Asp.net

11.1 How to emit client-side javascript blocks from VB.NET/C#?

The RegisterStartupScript method emits the script just before the closing tag of the Page object's <form
runat= server> element.

VB.NET

RegisterStartupScript("Sample", "<SCRIPT Language='javascript'>alert('Hello World');</SCRIPT>")


C#

RegisterStartupScript("Sample", "<SCRIPT Language='javascript'>alert('Hello World');</SCRIPT>");


Alternatively, use the RegisterClientScriptBlock method which emits the client-side script just after the
opening tag of the Page object's <form runat= server> element.

11.2 How to open a new Window using javascript function from a Link
button?

VB.NET

link.Attributes( "onClick" ) = "window.open( 'url', 'name', 'properties' )";


C#

link.Attributes[ "onClick" ] = "window.open( 'url', 'name', 'properties' )";


You can also check out Andy Smith's RemoteWindow Control

11.3 Is there a JavaScript Quick Reference Guide?

Here is a JavaScript Quick Reference Guide in Poster Format that you can print out and refer easily.
Covers the older and newer version of DOM and IE and Mozilla.
Danny Goodman's JavaScript and Browser Objects Quick Reference

11.4 How to set the background color of a web page using code behind?

Yes

      1. In the body tag, add runat="server" and give the tag an id (e.g. id="bodyID").
      2. In the class definition in the code-behind, add VB.NET


Protected bodyID As System.Web.UI.HtmlControls.HtmlGenericControl


C#

protected System.Web.UI.HtmlControls.HtmlGenericControl bodyID ;




bodyID.Attributes.Add("bgcolor", "green")
C#

bodyID.Attributes.Add("bgcolor", "green");




11.5 How to resolve error message "String constants must end with a
double quote."?

To resolve this check out PRB: The Tag Is Treated As a Closing Tag When Inside a Quoted String

11.6 Why can't I open a new browser window from within server code?

Server code executes on Server, whereas the new window is created on the client. You need to use client-
side script to open new window.

11.7 How to get the confirmation of Yes/No from a javascript pop-up and
display the value on the page?

Code Behind

Button1.Attributes.Add("onclick", "getMessage()")


Client Side

<SCRIPT language=javascript>
function getMessage()
{
var ans;
ans=window.confirm('Is it your confirmation.....?');

if (ans==true)
    {
       document.Form1.hdnbox.value='Yes';
    }
else
    {
       document.Form1.hdnbox.value='No';}
    }
</SCRIPT>


To display the Yes/No value selected by user, in your code behind file:

Response.Write(Request.Form("hdnbox"))




11.8 How to open a browser window with maximum size on click of a
button?

VB.NET
Button1.Attributes.Add("onclick", "window.open('page2.aspx','','fullscreen=yes')")


C#

Button1.Attributes.Add("onclick", "window.open('page2.aspx','','fullscreen=yes')");




11.9 How can I know if the client browser supports active scripting?

You can detect and interept the capabilities of your client using the namespace
System.Web.HttpBrowserCapabilities :
VB.NET

Dim browser As System.Web.HttpBrowserCapabilities = Request.Browser
Response.Write("Support ActiveXControl: " + browser.ActiveXControls.ToString())


C#

System.Web.HttpBrowserCapabilities browser = Request.Browser;
Response.Write ("Support ActiveXControl: " + browser.ActiveXControls.ToString ());


For more details Refer: Detecting Browser Types in Web Forms

11.10 How to determine if the Browser supports javascript?

VB.NET

if Page.Request.Browser.JavaScript then
...
else
...
end if


C#

if (Page.Request.Browser.JavaScript )
{
...
}
else
{
...
}




11.11 How can I change the scroll bar color?
Use Style Sheet to change the color of scroll-bar

body
{
FONT-SIZE: 8pt;
COLOR: #000000;
background-color: #EEEEEE;
scrollbar-face-color: #EEEE99;
scrollbar-highlight-color: #DDDDDD;
scrollbar-shadow-color: #DEE3E7;
scrollbar-3dlight-color: #FF6600;
scrollbar-arrow-color: #006699;
scrollbar-track-color: #EFEFEF;
scrollbar-darkshadow-color: #98AAB1;
}




11.12 How to create dynamic javascripts in server side code based on
server side variables?

Here's and example:

VB.NET

Dim value As String = "pic1.jpg"
Button1.Attributes("onMouseOver") = "alert( '" + value + "');"


C#

string value = "pic1.jpg";
Button1.Attributes["onMouseOver"] = "alert( \"" + value + "\");" ;




11.13 How can I use a Timer Control to refresh a page automatically at a
specified interval?



<asp:DropDownList id="DropDownList1" runat="server" onChange="SetClientRefresh(this);">
   <asp:ListItem Value="1000">1 second</asp:ListItem>
   <asp:ListItem Value="2000">2 seconds</asp:ListItem>
   <asp:ListItem Value="3000">3 seconds</asp:ListItem>
</asp:DropDownList>




<script language='javascript'>
var cTimeOut = null;
function SetClientRefresh(sel)
{
     var newRefresh = sel.options[sel.selectedIndex].value;
     if (cTimeOut != null)
     {
         window.clearTimeout(cTimeOut);
     }
     cTimeOut = window.setTimeout("ReLoadPage()", newRefresh);
}

function ReLoadPage()
{
   window.location.reload();
}
</script>




11.14 How to open a new window without IE menus and toolbars on click
of a button?

VB.NET

Button2 .Attributes.Add ("onclick", "window.open('webform1.aspx','_blank','toolbar=no')")


C#

Button2 .Attributes.Add ("onclick", "window.open('webform1.aspx','_blank','toolbar=no')");




11.15 Does JavaScript support hashtables/ hash tables or dictionary type
data structures?

All Objects in JavaScript implicitly support hash table like syntax by virtue of behaving as Associative
Arrays. Properties of an object can be accessed in 2 ways as shown below:

object.property = value;
object["property"] = value;


So, when used in a hash table like syntax as shown above, you will be simply creating dynamic properties
and assigning values to those properties.

11.16 How to disable the right click option on a web page?



<body oncontextmenu="return false;">
...
</body>


Note :User can still do a View/Source in their browser menu.
11.17 How to hide a control using javascript?



document.getElementById("<id>").style.visibility="hidden";




11.18 Can I modify WebUIValidation.js?

Extract from MSDN :

You are encouraged to read the script to see more of what is going on. However, it is not recommended
that you modify these scripts, because their function is very closely tied to a particular version of the run
time. If the run time is updated, the scripts may need a corresponding update, and you will have to either
lose your changes or face problems with the scripts not working. If you must change the scripts for a
particular project, take a copy of the files and point your project to them by overriding the location of the
files with a private web.config file.It is perfectly fine to change this location to be a relative or absolute
reference.


For more details refer ASP.NET Validation in Depth

11.19 How to change a Label element's text in javascript?



document.getElementById("Label1").innerText = "Changed Text";




11.20 How to resize two <div> tags on a webform?



<script>
function ResizeDivs()
{
var DivTop = document.getElementById('Top')
var DivBottom = document.getElementById('Bottom')
var BodyHeight = 0;

var DivTopHeight = 0;
var DivBottomHeight = 0;
var DivBottomPosition = 0;

BodyHeight = document.body.clientHeight;
DivBottomHeight = DivBottom.clientHeight;
DivBottom.style.top = BodyHeight - DivBottomHeight;
DivTop.style.height = DivBottom.style.top;

}

window.onload = ResizeDivs;
window.onresize = ResizeDivs;</script>




<div id="Top" style="position:absolute; top:0px; left:0px; background-color:#c0c0c0; overflow:auto;
width:100%">
Top Div Text:
<br>Syncfusion
<br>Sample code
<br>To
<br>autosize
<br><div>
<br>tag

</div>
<div id="Bottom" style="position:absolute; background-color:#808080; width:100%">
Bottom Div Text:
<br> Footer for the page
<br> Line1
<br> Line2
</div>


Note : if the DIV has no borders, clientHeight works. If you are going to be using a border or margins, then
use offsetHeight

11.21 How to check/ uncheck a checkbox based on the text entered in
textbox?



<asp:CheckBox id="CheckBox1" runat="server"></asp:CheckBox>
<asp:TextBox id="TextBox1" runat="server"></asp:TextBox>




<script type="text/javascript">
function chkTextEntered()
{
   document.getElementById("CheckBox1").checked = true;
   if(document.getElementById("TextBox1").value =="" )
   {
       document.getElementById("CheckBox1").checked = false;
   }
}
</script>


In Page_Load
VB.NET

TextBox1.Attributes.Add("onKeyDown", "chkTextEntered();")
C#

TextBox1.Attributes.Add("onKeyDown", "chkTextEntered();");




11.22 How to rotate a Label Text?



<asp:Label id="Label1" style="writing-mode:tb-rl" runat="server">Label</asp:Label>




11.23 How to display a message in the status bar of a browser window?



<body onload ="window.status='First Page'">
..
</body>




11.24 How to change the BackGroundColor of a page based on the value
selected in a DropdownList?



<asp:DropDownList id="DropDownList1" runat="server" AutoPostBack="True">
   <asp:ListItem Value="Red">Red</asp:ListItem>
   <asp:ListItem Value="Blue">Blue</asp:ListItem>
   <asp:ListItem Value="Green">Green</asp:ListItem>
</asp:DropDownList>


VB.NET

Page.RegisterClientScriptBlock("BodyStyle", "<style type='text/css'>body{background-color: " +
DropDownList1.SelectedItem.Value + ";}</style>")


C#

Page.RegisterClientScriptBlock("BodyStyle", "<style type='text/css'>body{background-color: " +
DropDownList1.SelectedItem.Value + ";}</style>");




11.25 How to disable a Dropdownlist once someone has selected an item in
the Dropdownlist?
<asp:DropDownList id="DropDownList1" runat="server">
   <asp:ListItem Value="Red">Red</asp:ListItem>
   <asp:ListItem Value="Blue">Blue</asp:ListItem>
   <asp:ListItem Value="Green">Green</asp:ListItem>
</asp:DropDownList>


VB.NET

DropDownList1.Attributes.Add("onChange","this.disabled=true;" )


C#

DropDownList1.Attributes.Add("onChange","this.disabled=true;" );




11.26 How can I make a Textbox a mandatory field if a checkbox is
checked on a button click event in the client side?



<asp:TextBox id="TextBox1" style="Z-INDEX: 101; LEFT: 32px; POSITION: absolute; TOP: 104px"
runat="server">
<asp:CheckBox id="CheckBox1" style="Z-INDEX: 102; LEFT: 24px; POSITION: absolute; TOP: 80px"
runat="server">
<asp:Button id="Button1" style="Z-INDEX: 103; LEFT: 32px; POSITION: absolute; TOP: 144px"
runat="server" Text="Button">




<script>
function func1()
{
    if(document.getElementById ("CheckBox1").checked==true)
   {
       if(document.getElementById("TextBox1").value=="")
       {
           alert("Enter something in textbox");
        }
   }

}
</script>


VB.NET

Button1.Attributes.Add ("onclick" , "return func1()");
C#

Button1.Attributes.Add ("onclick" , "return func1()");




11.27 Why does the SmartNavigation does not work on the live server but
works perfectly on the Development Machine?

May be the domain does not have access to the aspnet_client folder which is located in the wwwroot
folder. i.e the website is not able to find the scripts for smart navigation. So set up a virtual folder to the
wwwroot/aspnet_client and it will fix the problem.

11.28 How to pop up a message box when no item in the dropdownlist is
selected before postback?

        Make sure to add a ListItem with Text="Please Choose" and Value ="".
        Add a RequiredFieldValidator with ControlToValidate= <Dropdownlist1> and Display="None"
        Add a ValidationSummary with ShowMessageBox =true


<asp:DropDownList id="DropDownList1" runat="server">
   <asp:ListItem Value="">Please Choose</asp:ListItem>
   <asp:ListItem Value="Faq">Faq</asp:ListItem>
   <asp:ListItem Value="Tips">Tips</asp:ListItem>
   <asp:ListItem Value="Tricks">Tricks</asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator id="RequiredFieldValidator1" style="Z-INDEX: 102; LEFT: 176px;
POSITION: absolute; TOP: 48px"
   runat="server" ErrorMessage="Please Select an Item in the dropdownlist"
ControlToValidate="DropDownList1"
   Display="None"></asp:RequiredFieldValidator>
<asp:Button id="Button1" style="Z-INDEX: 104; LEFT: 128px; POSITION: absolute; TOP: 16px"
runat="server"
   Text="Button"></asp:Button>
<asp:ValidationSummary id="ValidationSummary1" style="Z-INDEX: 105; LEFT: 176px; POSITION:
absolute; TOP: 72px"
   runat="server" ShowMessageBox="True" ShowSummary="False"></asp:ValidationSummary>



Why is the DataList not displayed on the web page?

You must have missed the <ItemTemplate> tag

<asp:DataList id="DataList1" runat="server">
<ItemTemplate>
   <%#DataBinder.Eval(Container.DataItem, "FieldName").ToString()%>
</ItemTemplate>
</asp:DataList>
7.2 How to change the colors of a row to indicate its the Birthday of the
Employee (for example) in a DataList?



<asp:datalist id="DataList1" OnItemDataBound ="ItemDB" GridLines="Both" RepeatColumns="2"
runat="server" ShowHeader="true">
   <HeaderStyle Font-Bold="True" HorizontalAlign="Center" Font-Name="verdana" Font-
Size="10pt"></HeaderStyle>
   <ItemStyle Font-Size="10pt"></ItemStyle>
   <Headertemplate>
      Employee Details
   </Headertemplate>
   <ItemTemplate>
      <%#DataBinder.Eval(Container.DataItem,"LastName")%>
      ,
      <%#DataBinder.Eval(Container.DataItem,"FirstName")%>
      <br>
      HireDate :
      <%#DataBinder.Eval(Container.DataItem,"HireDate")%>
      <br>
   </ItemTemplate>
</asp:datalist>




7.3 How to group the data in the DataList?



<asp:DataList id="DataList1" runat="server" onItemDataBound="ItemDB">
<HeaderTemplate >
<table width=100%>
</HeaderTemplate>
<ItemTemplate>
<tr><td>
<asp:Label Runat=server
text=<%#DataBinder.Eval(Container.DataITem, "Title")%> ID="lblTitle">
</asp:Label>
<td><asp:Label Runat=server
text=<%#DataBinder.Eval(Container.DataITem, "LastName")%> ID="lblLastName">
</asp:Label>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:DataList>

End Sub
7.4 Which control should I use when binding a multidimensional array?

Use a DataList as follows. .aspx

<asp:datalist id="DataList1" runat="server">
<ItemTemplate>
   <asp:repeater datasource="<%#Container.DataItem%>" runat=server ID="Repeater1" >
   <ItemTemplate>
         <%# Container.DataItem %>
   </ItemTemplate>
   </asp:repeater>
</ItemTemplate>
</asp:datalist>




7.5 How to display data in multiple columns for a specific Column in a
table in an ASP.NET page?

Use a DataList control and set RepeatColumns= n
n=>Number of columns

7.6 How to use a Hyperlink in a DataList?



<asp:DataList id="DataList1" runat="server">
   <ItemTemplate>
   <asp:HyperLink Runat =server NavigateUrl ='<%#"webform1.aspx?id=" +
DataBinder.Eval(Container.DataItem, "productid").ToString()%>' ID="Hyperlink1">
      <%#DataBinder.Eval(Container.DataItem, "ProductName")%>
   </asp:HyperLink>
   </ItemTemplate>
</asp:DataList>




7.7 How to do Paging in DataList?



<asp:datalist id="DataList1" runat="server">
   <ItemTemplate>
      <%#DataBinder.Eval(Container.DataItem, "ProductID").ToString()%>
      <%#DataBinder.Eval(Container.DataItem, "ProductName").ToString()%>
   </ItemTemplate>
</asp:datalist>
<table width="50%" border="0">
   <tr>
      <td><asp:LinkButton id="lnkPrevious" runat="server"><<</asp:LinkButton>
      <td><asp:LinkButton id="lnkNext" runat="server">>></asp:LinkButton>
   </tr>
</table>
7.8 How to hide and show data in the DataList?



<asp:Datalist runat="server" OnItemCommand ="ItemCmd" id="Datalist1" Font-Size="10pt" Font-
Name="Verdana">
   <ItemTemplate>
      <asp:LinkButton style="text-decoration:none" runat="server" id="btnDetails" Text="+"
CommandName="Show" Font-Name="Verdana" />
      <b>
      <%# DataBinder.Eval(Container.DataItem, "employeeid") %>
      </b>
      <br />
      <asp:label id="lblEID" Visible="False" runat="Server" Text='<%#
DataBinder.Eval(Container.DataItem, "Employeeid") %>' />
      <asp:DataGrid runat="server" id="Datagrid1" Font-Name="Verdana" Font-Size="10pt"
HorizontalAlign="Center"
             Visible="False" Width="85%">
   </ItemTemplate>
</asp:Datalist>



7.9 How to add a Templatecolumn dynamically to a DataList?



<asp:DataList id="DataList1" runat="server"></asp:DataList>



7.10 How to create a File Picker in ASP.NET?

Use namespace System.IO

<asp:label id="lblHeader" runat="server"></asp:label><br>
<b>Get Information on Directory:</b><br>
<p><asp:textbox id="txtPath" runat="server"></asp:textbox>
<p></p>
<asp:button id="btnSubmit" runat="server" text="Go!" type="Submit"></asp:button>
<p></p>
<div style="width:100%; height:200; overflow:auto;">
<asp:datalist id="DataList1" runat="server" DataKeyField="FullName"
OnSelectedIndexChanged="SelectedIndexChanged">
    <ItemTemplate>
    <li>
       <%# DataBinder.Eval(Container.DataItem, "Name") %>
       <br>
       <font size="-1">[
       <asp:linkbutton Text="View Contents" CommandName="Select" runat="server" ID="Linkbutton1"
/>]
          |[
      <%# DataBinder.Eval(Container.DataItem, "Length") %>
      bytes] </font>
      <p>
   </ItemTemplate>
</asp:datalist>
</div>
<p>
<hr>
</p><asp:label id="lblFileContents" runat="server"></asp:label>




7.11 How can I get a list of all the environment variables?

VB.NET

<asp:DataList id="DataList1" runat="server">
   <HeaderTemplate>
   <table>
   </HeaderTemplate>
   <ItemTemplate>
   <tr>
   <td>
      <%# CType(Container.DataItem, DictionaryEntry).Key %>
   </td>
   <td>
      <%# CType(Container.DataItem, DictionaryEntry).Value%>
   </td>
   </tr>
   </ItemTemplate>
   <FooterTemplate>
   </table>
   </FooterTemplate>
</asp:DataList>




Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
MyBase.Load
   'Put user code to initialize the page here
   DataList1.DataSource = System.Environment.GetEnvironmentVariables()
   DataList1.DataBind()
End Sub


C#

<asp:DataList id="DataList1" runat="server">
   <HeaderTemplate>
   <table>
   </HeaderTemplate>
   <ItemTemplate>
   <tr>
   <td>
      <%# ((DictionaryEntry)Container.DataItem).Key %>
   </td>
   <td>
      <%# ((DictionaryEntry)Container.DataItem).Value %>
   </td>
   </tr>
   </ItemTemplate>
   <FooterTemplate>
   </table>
   </FooterTemplate>
</asp:DataList>




private void Page_Load(object sender, System.EventArgs e)
{
   // Put user code to initialize the page here
   DataList1.DataSource = System.Environment.GetEnvironmentVariables();
   DataList1.DataBind();
}




7.12 How to display checkbox in a DataList and highlight a row if the value
of checkbox is true?



<asp:datalist id="DataList1" OnItemDataBound ="ItemDB" runat="server">
<ItemTemplate >
<asp:CheckBox id="chkDiscontinued" Runat =server
   checked=<%#Convert.ToBoolean(DataBinder.Eval(Container.DataItem ,
"Discontinued").ToString())%>>
</asp:CheckBox>
<asp:label ID="lblName" runat=server text=<%#DataBinder.Eval(Container.DataItem ,
"ProductName").ToString() %>></asp:label>
</ItemTemplate>
</asp:datalist>




7.13 How to display all System Colors in a DataList?



<asp:DataList id="DataList1" runat="server" >
<HeaderTemplate ><table></HeaderTemplate>
<ItemTemplate >
<tr>
   <td bgcolor =<%#Container.DataItem%> runat=server id="td">
   <%#Container.DataItem%>
   </td>
</tr>
</ItemTemplate>
<FooterTemplate></table></FooterTemplate>
</asp:DataList>

								
To top