Thursday, November 20, 2008

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

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





1 . What is the difference between URL and URI?

A URL is the address of some resource on the Web, which means that normally you type the address into a browser and you get something back. There are other type of resources than Web pages, but that's the easiest conceptually. The browser goes out somewhere on the Internet and accesses something.

A URI is just a unique string that uniquely identifies something, commonly a namespace. Sometimes they look like a URL that you could type into the address bar of your Web browser, but it doesn't have to point to any physical resource on the Web. It is just a unique set of characters, that, in fact, don't even have to be unique.

URI is the more generic term, and a URL is a particular type of URI in that a URL has to uniquely identify some resource on the Web.

2 . How to convert milliseconds into time?

TimeSpan ts = TimeSpan.FromMilliseconds(10000);
Response.Write (ts.ToString () );
3 . How to include multiple vb/cs files in the source?

You can do this using assembly directives.

or

However, note that each source file will be compiled individually into its own assembly, so they cannot have dependencies on each other.

4 . How to convert a string to Proper Case?

Use the namespace System.Globalization

string myString = "syncFusion deVeloPer sUppOrt";
// Creates a TextInfo based on the "en-US" culture.
TextInfo TI = new CultureInfo("en-US",false).TextInfo;
Response.Write (TI.ToTitleCase( myString ));

For more details refer TextInfo.ToTitleCase()

5 . How can I ensure that application-level variables are not updated by more than one user simultaneously?

Use the HttpApplicationState's Lock and UnLock methods.

For more details refer : MSDN: Application State



7 . How to validate that a string is a valid date?

bool blnValid=false;
try
{
DateTime.Parse(MyString);
blnValid=true;
}
catch
{
blnValid=false;
}

8 . Are namespaces and Class names Case Sensitive?

Namespaces and Class names are case Sensitive. Namespaces imported using the @ Import Directive will cause an error if the correct case is not used.

9 . How to convert string to a DateTime and compare it with another DateTime?
bool blntimeIsOk = (DateTime.Parse("15:00") <>

10 . How to get the url of page dynamically?
Use Request.Url property

11 . How to convert user input in dMy format to Mdy?
DateTime dt = DateTime.ParseExact("0299", new string[] {"My","M/y"}, null,System.Globalization.DateTimeStyles.None); For more details refer DateTime.ParseExact

12 . When the User is prompted a File Download dialogbox, if the user selects "Save" then the "Save as" dialog box is displayed. Is there any way for me to retrieve the filename and directory path specified by the user on the File Download dialog box?

Clients do not report information back about where the user selects to save the content, so there isn't an easy way to do this. Instead, you would need to ask the user before using the content-disposition for a file path, and then you could specify the filename parameter for the content-disposition header. Still, the user is free to change that path when actually downloading.

13 . How to hide or show Controls in server side code?
In any appropriate event write VB.NET TextBox1.Visible =not TextBox1.Visible C# TextBox1.Visible =!TextBox1.Visible ;

14 . How to check if the user is using a secure or non secure connection? The Request Object defines a Property called IsSecureConnection, that will indicate whether http:// or https:// has been used. 15 . Is it possible to write code in many languages in one ASP.NET project? You cannot write the code-behind files in different languages in the same project, but you can write the aspx pages and ascx controls in different languages.

16 . What is the difference between Response.Redirect() and Server.Transfer().

Response.Redirect
* Tranfers the page control to the other page, in other words it sends the request to the other page.
* Causes the client to navigate to the page you are redirecting to. In http terms it sends a 302 response to the client, and the client goes where it's told. Server.Transfer
* Only transfers the execution to another page and during this you will see the URL of the old page since only execution is transfered to new page and not control.
* Occurs entirely on the server, no action is needed by the client Sometimes for performance reasons, the server method is more desirable

17 . How to get the hostname or IP address of the server?
You can use either of these:
* HttpContext.Current.Server.MachineName
* HttpContext.Current.Request.ServerVariables["LOCAL_ADDR"] The first one should return the name of the machine, the second returns the local ip address. Note that name of the machine could be different than host, since your site could be using host headers

18 . What is the meaning of validateRequest=true in .net framework1.1?
The value of validateRequest is set to 'true' by default, which means that the framework will automatically deny submission of the '<' and '>' characters.

19 . What is the different between and ?

The is used for databinding where as is used to output the result of an expression. The expression inside will be executed only when you call the page's or control's DataBind method. The expression inside will be executed and displayed as and when it appears in the page.

20 . What permissions do ASP.NET applications posses by default?

By default ASP.NET Web applications run as ASP.NET user. This user has limited permissions equivalent to the User Group.

21 . How can I specify the relative path for a file?

Suppose you have following file hierarchy:

default.aspx
Admin/login.aspx
Misc/testpage.aspx



And you are on the login.aspx and want your user to navigate to the default.aspx (or testpage.aspx) file. Then you can use

* Response.Redirect ("../default.aspx")
* Response.Redirect ("../Misc/testpage.aspx")

22 . How can I specify the "upload a file" input textbox in a form to be read only so that the user can click on the browse button and pick a file but they cannot type anything into the textbox next to the browse button.



23 . How to change the Page Title dynamically?

//Declare
protected System.Web.UI.HtmlControls.HtmlGenericControl Title1 ;

//In Page_Load
Title1.InnerText ="Page 1" ;

24 . Why do I get the error message "Object must implement IConvertible". How can I resolve it?

The common cause for this error is specifying a control as a SqlParameter's Value instead of the control's text value.
For example, if you write code as below you'll get the above error:

SqlParameter nameParameter = command.Parameters.Add("@name", SqlDbType.NVarChar, 50);
nameParameter.Value = txtName ;

To resolve it, specify the control's Text property instead of the control itself.

nameParameter.Value =txtName.Text;

25 . Why is default.aspx page not opened if i specify http://localhost. I am able to view this page if i hardcode it as http://localhost/default.aspx?

If some other default page comes higher in the list, adjust the default.aspx to be the number one entry inside the IIS configuration. If you have multiple websites inside IIS, make sure the configuration is applied on the right website (or on all websites by applying the configuration on the server-level using the properties dialog, configure WWW service).

26 . Can ASP.NET work on an NT server?

No. For more details refer ASP 1.1 version

27 . Is it possible to migrate Visual InterDev Design-Time Controls to ASP.NET?

Refer INFO: Migrating Visual InterDev Design-Time Controls to ASP.NET

28 . How to automatically get the latest version of all the asp.net solution items from Source Safe when opening the solution?

In VS.NET you can go to Tools > Options > Source Control > General and check the checkbox for Get everything when a solution opens.
This retrieves the latest version of all solution items when you open the solution.

29 . How to make VS.Net use FlowLayout as the default layout rather than the GridLayout?


For C#, go to path C:\Program Files\Microsoft Visual Studio .NET 2003\VC#\VC#Wizards\CSharpWebAppWiz\Templates\1033
Change the following line in the existing WebForm1.aspx

to

Note:Before changing any templates it's a good idea to make backup copies of them
Or rather than above approach you can change the behavior for new files on a per project basis in Visual Studio by:

1. Right clicking on the project name (Ex: "WebApplication1)" in Solution Explorer, and select "Properties".
2. From project properties window, under Common Properties>Designer Defaults>Page Layout change "Grid" to "Flow".


30 . Can I use a DataReader to update/insert/delete a record?

No. DataReader provides a means of reading a forward-only stream of rows from a database.


31 . How to format a Telphone number in the xxx-xxx-xxxx format?


double Telno= double.Parse(ds.Tables[0].Rows[0]["TelNo"].ToString());
Response.Write(Telno.ToString("###-###-####"));
32 . Can two different programming languages be mixed in a single ASPX file?

No. ASP.NET uses parsers to strip the code from ASPX files and copy it to temporary files containing derived Page classes, and a given parser understands only one language

33 . Can I use custom .NET data types in a Web form?

Yes. Place the DLL containing the type in the application root's bin directory and ASP.NET will automatically load the DLL when the type is referenced. This is also what happens when you add a custom control from the toolbox to your web form.


Your Ad Here

0 comments:

Respects for your's Questions & Opinions

  • Friends
  •  

    Recent Posts

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