Thursday, November 20, 2008

Dot Net - Asp.Net - Basic I(FAQ'S)

0 comments 11/20/2008
Sign up to receive our site updates!










1 . What is ASP.NET?

ASP.NET is a programming framework built on the common language runtime that can be used on a server to build powerful Web applications.



2 . Why does my ASP.NET file have multiple tag with runat=server?

This means that ASP.Net is not properly registered with IIS.

.Net framework provides an Administration utility that manages the installation and uninstallation of multiple versions of ASP.NET on a single machine. You can find the file in C:\WINNT\Microsoft.NET\Framework\v**\aspnet_regiis.exe

use the command: aspnet_regiis.exe -u ---> to uninstall current asp.net version.

use the command: aspnet_regiis.exe -i ---> to install current asp.net version.



For Windows Server 2003, you must use aspnet_regiis -i -enable

This is because of the "Web Service Extensions" feature in IIS 6

(if you install VS.NET or the framework without IIS installed, and then go back in and install IIS afterwards, you have to re-register so that ASP.NET 'hooks' into IIS properly."



3 . How to find out what version of ASP.NET I am using on my machine?



Response.Write(System.Environment.Version.ToString() );



4 . Is it possible to pass a querystring from an .asp page to aspx page?

Yes you can pass querystring from .asp to ASP.NET page .aspx

Response.Write (Request["id"].ToString ());



5 . How to comment out ASP.NET Tags?



6 . What is a ViewState?

In classic ASP, when a form is submitted the form values are cleared. In some cases the form is submitted with huge information. In such cases if the server comes back with error, one has to re-enter correct information in the form. But submitting clears up all form values. This happens as the site does not maintain any state (ViewState).

In ASP .NET, when the form is submitted the form reappears in the browser with all form values. This is because ASP .NET maintains your ViewState. ViewState is a state management technique built in ASP.NET. Its purpose is to keep the state of controls during subsequent postbacks by the same user. The ViewState indicates the status of the page when submitted to the server. The status is defined through a hidden field placed on each page with a

control.

If you want to NOT maintain the ViewState, include the directive at the top of an .aspx page If you do not want to maintain Viewstate for any control add the attribute EnableViewState="false" to any control. For more details refer The ASP.NET View State



7 . Where can I get the details on Migration of existing projects using various technologies to ASP.NET?

Microsoft has designed Migration Assistants to help us convert existing pages and applications to ASP.NET. It does not make the conversion process completely automatic, but it will speed up project by automating some of the steps required for migration.

Below are the Code Migration Assistants

* ASP to ASP.NET Migration Assistant

* PHP to ASP.NET Migration Assistant

* JSP to ASP.NET Migration Assistant

Refer Migrating to ASP.Net



8 . What is the equivalent of date() and time() in ASP.NET?

System.DateTime.Now.ToShortDateString();

System.DateTime.Now.ToShortTimeString();



9 . How to prevent a button from validating it's form?

Set the CauseValidation property of the button control to False



10 . How to get the IP address of the host accessing my site?

Response.Write (Request.UserHostAddress.ToString ());



11 . How to access the Parameters passed in via the URL?

Call the Request.QueryStringmethod passing in the key. The method will return the parameter value associated with that key. VB.NET

Request.QueryString["id"];



12 . How to display a Wait page while a query is running?

Refer Asynchronous Wait State Pattern in ASP.NET



13 . How to implement Form based Authentication in ASP.NET application?

In web.config

system.web

authentication mode="Forms"

forms loginUrl ="Default.aspx"

authentication

authorization

deny users ="?"

authorization

system.web

14 . How to catch the 404 error in my web application and provide more useful information?

In the global.asax Application_error Event write the following code

Exception ex = Server.GetLastError().GetBaseException();

if (ex.GetType() == typeof(System.IO.FileNotFoundException))

{

//your code

Response.Redirect ("err404.aspx");

}

else

{

//your code

}



15 . Is there a method similar to Response.Redirect that will send variables to the destination page other than using a query string or the post method?

Server.Transfer preserves the current page context, so that in the target page you can extract values and such. However, it can have side effects; because Server.Transfer doesnt' go through the browser, the browser doesn't update its history and if the user clicks Back, they go to the page previous to the source page.

Another way to pass values is to use something like a LinkButton. It posts back to the source page, where you can get the values you need, put them in Session, and then use Response.Redirect to transfer to the target page. (This does bounce off the browser.) In the target page you can read the Session values as required.

Refer to Passing Values Between Web Forms Pages for more information.



16 . What are the differences between HTML versus Server Control?

Refer

* ASP.NET Server Controls Recommendations

* Introduction to ASP.NET Server Controls



17 . How can I change the action of a form through code?

You can't change it. The action attribute is owned by ASP.NET. Handle Events and Transfer.

For work around refer to Paul Wilson's Multiple Forms and Non-PostBack Forms - Solution



18 . Is there any control that allows user to select a time from a clock - in other words is there a clock control?

Peter Blum has developed some controls. Check out Peter's Date Package: TimeOfDayTextBox and DurationTextBox Controls



19 . How to Compare time?

string t1 = DateTime.Parse("3:30 PM").ToString("t");

string t2 = DateTime.Now.ToString("t");

if (DateTime.Compare(DateTime.Parse (t1), DateTime.Parse (t2)) <>

{

Response.Write(t1.ToString() + " is <>

}

else

{

Response.Write(t1.ToString() + " is > than " + t2.ToString());

}



20 . How To work with TimeSpan Class?

DateTime adate = DateTime.Parse("06/24/2003");

DateTime bdate = DateTime.Parse("06/28/2003");

TimeSpan ts = new TimeSpan (bdate.Ticks - adate.Ticks);

Response.Write(ts.TotalDays.ToString () + "

");

Response.Write(ts.TotalHours.ToString() + ":" + ts.TotalMinutes.ToString() + ":" + ts.TotalSeconds.ToString() + ":" + ts.TotalMilliseconds.ToString() );



21 . Where can I get information on Cookies in ASP.NET?

Refer Mike Pope's article Basics of Cookies in ASP.NET



22 . Does ASP.Net still recognize the global.asa file?

ASP.Net does not recognize the standard ASP global.asa file. Instead it uses a file named global.asax with the same - plus additional - functionality.



23 . How should I destroy my objects in ASP.Net?

ASP.Net actually has very solid internal garbage collection. So this is not an issue as it was in previous versions of Active Server Pages.

Link to more information: Element



24 . Are there resources online with tips on ASP to ASP.Net conversions?

Microsoft has deisnged The ASP to ASP.NET Migration Assistant help us convert ASP pages and applications to ASP.NET. It does not make the conversion process completely automatic, but it will speed up project by automating some of the steps required for migration.

The following Code Migration Assistants are discussed in the link below.

* ASP to ASP.NET Migration Assistant

* PHP to ASP.NET Migration Assistant

* JSP to ASP.NET Migration Assistant

Refer Migrating to ASP.Net

Also refer:

* Microsoft's ASP to ASP.NET Code Migration Assistant

* John Peterson's article Microsoft's ASP to ASP.NET Migration Assistant

* Paolo Cavone's article From ASP to ASP.NET... Painlessly!



25 . How do I publish my ASP.NET application to my ISP's web server?

Your ISP must first create an IIS application and apply the Front Page Server Extensions to it. Then in Visual Studio .NET, select the "Project | Copy Project" menu. Then enter the URL and select the FrontPage web access method. The "Copy Project" feature copies all of the necessary files to your ISP's machine for your ASP.NET application to run.

You can also FTP your files to your ISP web server. But you must know which files to upload. For more details refer PRB: Remote ASP.NET Projects Require IIS on the Client Computer or FrontPage Server Extensions on the Server Computer



26 . Why do i get error message "Could not load type" whenever I browse to my ASP.NET web site?

Your code-behind files for either your .aspx or the global.aspx page have not been complied. Use Visual Studio .NET's "Build | Build Solution" menu, or run the command line compiler.

For more details refer PRB: "Could not load type" error message when you browse to .aspx page



27 . Will the WebMatrix SqlDataSourceControl work with a MySQL connection?

SqlDataSourceControl lets you connect and work with MS SQL DB, while AccessDataSourceControl do the same thing but for MS Access DB. Therefore SqlDataSourceControl can't help you in your MySql connectivity .

For Connectivity with MySql refer Accessing MySQL Database with ASP.NET



28 . Can I combine classic ASP and ASP.NET pages?

No.

ASP pages can run in the same site as ASP.NET pages, but you can't mix in a page. Also ASP and ASP.NET won't share their session.



29 . What is the difference between src and Code-Behind?

Src attribute means you deploy the source code files and everything is compiled JIT (just-in-time) as needed. Many people prefer this since they don't have to manually worry about compiling and messing with dlls -- it just works. Of course, the source is now on the server, for anyone with access to the server -- but not just anyone on the web.

CodeBehind attribute doesn't really "do" anything, its just a helper for VS.NET to associate the code file with the aspx file. This is necessary since VS.NET automates the pre-compiling that is harder by hand, and therefore the Src attribute is also gone. Now there is only a dll to deploy, no source, so it is certainly better protected, although its always decompilable even then.



30 . How can I get the value of input box with type hidden in code-behind?

You can set the runat= server for the hidden control and you can use ControlName.Value to get its value in CodeBehind file



31 . I have created a .NET user control page (.ascx) but I cannot compile and run it.

User control (ascx) can't be run on it own, but you can drag it onto any web page (aspx) and then run it.



32 . What is a .resx file?

The .resx resource file format consists of XML entries, which specify objects and strings inside XML tags. This is useful for localization. For more details refer Resources in .resx files

33 . Is it possible to use a style sheet class directly on a control instead of using inline or page-level formatting ?

Every WebControl derived control has a CssClass property which allows you to set it's format to a style sheet.



34 . Can I recieve both HTML markup for page and code in the ASP.NET web page's source code portion in the Web browser?

No. The Web browser recieves only HTML markup.

No source code or web control syntax is passed back to the web browser.



35 . Why can't I put where at the top of an ASPX file and write my server-side scripts in C ?

The parsers ASP.NET uses to extract code from ASPX files understand C#, Visual Basic.NET, and JScript.NET. You can write server-side scripts in any language supported by a .NET compiler.



36 . ASP pages that worked pefectly on Windows 2000 Server and IIS 5.0 do not work on Windows 2003 Server with IIS 6.0. ASP.NET pages work fine. Why?

Start -> Settings -> Control Panel -> Administrative Tools -> and double clicking IIS Manager.

Go to the Web Service Extensions tab, click Active Server Pages, then press the "Allow" button on the left



37 . Why do I get error message "Error creating assembly manifest: Error reading key file 'key.snk' -- The system cannot find the file specified"?

Check the location of the key.snk file relative to the assembly file. Provide an explicit path or a relative path.



38 . How to get URL without querystring?

string stringUri = "http://www.syncfusion.com/?id=1&auid=16";

Uri weburi = new Uri(stringUri);

string query = weburi.Query;

string weburl = stringUri.Substring(0, stringUri.Length - query.Length);

Response.Write (weburl);



39 . What is the best way to output only time and not Date?

Use DateTime as follows

Response.Write(DateTime.Now.ToString("hh:mm:ss"));



40 . Do I have to compile code if I am changing the content of my aspx.cs file?

Yes if you have used Codebehind="my.aspx.cs".

Not if you used src="my.aspx.cs" in your page declaration.



41 . How to grab the referring URL?

Response.Write ( Request.UrlReferrer.ToString());



Your Ad Here

0 comments:

Respects for your's Questions & Opinions

  • Friends
  •  

    Recent Posts

    New Comments

    Copyright 2008 All Rights Reserved Tech Tasks Template by Rajesh Kumar Chekuri

    Share
    Me
    Twitter Facebook Google +1 Pinterest Delicious Digg Stumbleupon More

    Connect to TT Facebook Google +1
    Back to Top