Tuesday, March 25, 2008

important questions

What is differnace between Response.Redirect and Server.Transfer
Server.Transfer is based on HttpServerUtility.Transfer Method and Response.Redirect is based on HttpResponse.Redirect Method
1.Response.Redirect is applicable towards the redirection of webpage between 2 applications Server.Transfer is used when redirecting the webpage with in the same application

2.Resonse.redirect can be used both for aspx and html pages.server.transfer is only used for aspx pages it will not work for html pages.

3. Response.Redirect the browser's history is updatedServer.Transfer the browser's history is not updated
4.
Response.Redirect the url is changed Server.Transfer is maintained the current url from where request is made.

What is location tab in web config file.

The location tag is used for coustomize the particular page or folder of website.






How to add css programmatically
For this we have to code on Page_Init event. and use htmlLink class.object of htmlLink class we set the href property and other attributes of styles an add this on header controlcode snip are following
protected void Page_Init(object sender, EventArgs e)
{
HtmlLink css = new HtmlLink();
css.Href = "css/fancyforms.css";
css.Attributes["rel"] = "stylesheet";
css.Attributes["type"] = "text/css";
css.Attributes["media"] = "all";
Page.Header.Controls.Add(css);

}

How you can determaine which control reason to postback.
this information is stored on viewstate __EVENTTARGET SO we can fetch it for find the control
fcode is follows


public static Control GetPostBackControl(Page page)
{
Control postbackControlInstance = null;

string postbackControlName = page.Request.Params.Get("__EVENTTARGET");
if (postbackControlName != null && postbackControlName != string.Empty)
{
postbackControlInstance = page.FindControl(postbackControlName);
}
else
{
// handle the Button control postbacks
for (int i = 0; i < postbackcontrolinstance =" page.FindControl(page.Request.Form.Keys[i]);" postbackcontrolinstance ="=" i =" 0;" postbackcontrolinstance =" page.FindControl(page.Request.Form.Keys[i].Substring(0," cause =" GetPostBackControl(Page);" style="color: rgb(51, 51, 255);">How you can off line your website.
we have to upload app_offline.htm on root of our website.

What is difference between relative and absolute URL.

Very often we have a relative URL of some page or resource like "~/img/logo.gif" and we need an absolute URL to insert it in some control or link (something like "http://www.ourserver.com/img/logo.gif")

How we can add multiple meta tag dynamicaly.

for this we have to use page_Init event and create object of HtmlMeta classand set the name and content property of the ojbect.
code snips is follows :-
protected void Page_Init(object sender, EventArgs e)
{
HtmlMeta meta1 = new HtmlMeta();
meta1.Name = "8888888888888888888888";
meta1.Content = "88888888";
this.Page.Header.Controls.Add(meta1);

HtmlMeta meta2 = new HtmlMeta();
meta2.Name = "aaaaa";
meta2.Content = "aaaa aaaaaaaa";
this.Page.Header.Controls.Add(meta2);
}
think to remmberThis also works with MasterPages. Just place this code in your content page.

Is session end event of global.aspx file always fired ?
No. Session End event fires only when Session Mode is set to InProc.


What is System.Environment.Exit(0);

It will udrill the OS depend on the integer value passed in it.
so u got message required resourse in not availbale


What are the differences between <%# %>and <%= %>?

The is used for data binding 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 when it appears on the page.



Why can’t I step into a DLL’s source code from ASP.NET application while debugging?

First of all, if you are using the ‘Release’ build of the modules, please try building the modules or application under ‘Debug’ build.

If the debugger cannot load the DLL's .PDB file, we also cannot use the source code. The PDB files are debug symbols that are generated with the modules (EXE/DLL). They hold the necessary information for source code level debugging. The debugger will not load a PDB that does not match the binary being debugged (For more information, see http://msdn.microsoft.com/en-us/library/ms241903.aspx. You can check if the debugger loads this PDB file by using the following steps:

1.
Start debugging.
2.
Click ‘Debug’ menu and then select ‘Windows’ to enter the ‘Modules’ window.
3.
Locate your DLL module to see if the PDB file is loaded. If the PDB file is not loaded, you can load it manually by right clicking the DLL module and then select ‘Load Symbols’ option).



During a debugging session, why isn’t the break point hit?

There are several reasons why this could happen:

1. Matching symbols cannot be found without symbols, breakpoints cannot be mapped from source code to machine code while it is being executed.
2. The source code you have opened inside Visual Studio 2005 does not match the build of the executable code you’re trying to debug. If you are aware of this but want the debugger to attempt to set the breakpoint anyway, you can do one of following:
2.1. Right click on the breakpoint and choose ’Location…’ Then check the ’Allow the source code to be different from the original version’ checkbox.
2.2. Turn off source code verification. Go to the menu Tools->Options->Debugging->General and uncheck ‘Require source files to exactly match the original version’.
3. The component or program you have set the breakpoint to, have not been loaded into the memory yet. When a DLL or component is loaded to your program, the debugger is notified and will attempt to ‘bind’ the breakpoint so that it can be hit.



How to speed up your ASP.NET pages?

You can improve your ASP.NET application performance using:

*
Use Page.IsPostBack
*
Use SQL Server Stored Procedures for Data Access
*
the HttpServerUtility.Transfer method
*
Save View State Only When Necessary.
*
Don't Rely on Exceptions.
*
Restrict Use of Session State.
*
Limit ASP.NET Server Controls
*
Precompile Your Apps
*
Use ASP.NET Caching

For more information, please refer to: Speed Up Your ASP.NET Pages and Developing High-Performance ASP.NET Applications.



What does the character ‘~’ mean in ASP.NET applications?

The character tilde (~) in the ASP.NET paths points to the root of the web application.

Web developers are familiar with using relative paths for all links, including hyperlinks, images and style sheets to be able to move around web pages collectively.

In ASP.NET when using User controls the relative paths can be difficult to use. The typical solution to this is to use web-root absolute paths instead here, such as ’~/UserControl1.ascx’, resulting in the hard-coded sub-directories that are common on ASP.NET sites.

The correct solution to this problem is to use app-relative paths instead, which ASP.NET nicely makes possible through the use of the tilde (~) prefix. Instead of [a href="/UC/Page.aspx"], use [a id="A1" href="~/Page.aspx" runat="server"]. The same ~ notation works for images also, as long as you add runat="server". There is also a ResolveUrl method that allows you to use ~ in your own code, which is one possible way to get stylesheet paths app-relative.

For more information about ASP.NET Web Site Paths, please see:

http://msdn.microsoft.com/en-us/library/ms178116.aspx.




What are the differences between ‘System.Net.Mail’ and ‘System.Web.Mail’?

System.Web.Mail and System.Net.Mail are both built-in libraries provided by Microsoft in .NET framework. System.Web.Mail is supported by all versions of .Net Frameworks at the moment. However, System.Web.Mail is obsolete since .Net 2.0 could be removed from the class library in the future. In .Net 2.0, the new ‘System.Net.Mail’ namespace is intrdocued. It is recommend against ‘System.Web.Mail’, if you are developing applications targeting .Net 2.0 and later.



Explain this code

myClass Object_Name = new myClass();
or
myClass Object_Name;

Object_Name = new myClass();

you are doing two things at once here: Setting up the variable in memory, and then creating a new Object.

Now that we've created an object, we can go ahead and call the one method that is in our Class.

Now that you have an Object , you can use the dot notation to call your Method:

Object_Name.Method_Name( )

How do I use Web Service in ASP.NET 2.0?

1. Before calling Web Service in ASP.NET, you need to create a Web Service and add a Web Reference into ASP.NET. You can get more information from the following link: http://www.asp.net/learn/videos/video-280.aspx.
2. There are two approaches for calling the Web Service, one is the synchronous approach, the other is the asynchronous approach.
Synchronous approach for calling Web Service:
YourWebServiceName.Service someWS = new YourWebServiceName.Service(); someWS.WebServiceMethod();
Asynchronous approach for calling Web Service:
YourWebServiceName.Service someWS = new YourWebServiceName.Service(); System.AsyncCallback cb = new AsyncCallback(showmsg);
someWS.BeginWebServiceMethod(cb, someWS);
void showmsg(IAsyncResult ar)
{ YourWebServiceName.Service someWS = (YourWebServiceName.Service)ar.AsyncState;
Response.Write(someWS.EndWebServiceMethod(ar));
}

How you can manage multiple fileupload button on page or what is HttpFileCollection Class

The following example demonstrates how to access the HttpFileCollection collection returned from the Files property of the HttpRequest object. The HttpFileCollection collection is populated by two FileUpload controls on the Web page. Items in the file collection are displayed in a BulletedList control.


[script runat="server"]

protected void Button1_Click(object sender, EventArgs e)
{
// Clear the BulletedList.
BulletedList1.Items.Clear();

// Check to see if at least one file was specified.
if (FileUpload1.HasFile | FileUpload2.HasFile)
{
Label1.Text = "The file collection consists of:";

// Get the HttpFileCollection.
HttpFileCollection hfc = Request.Files;
foreach (String h in hfc.AllKeys)
{
// Add an item to the BulletedList if a file
// was specified for the corresponding control.
if (hfc[h].ContentLength ] 0)
BulletedList1.Items.Add(Server.HtmlEncode(hfc[h].FileName));
}

}
else
{
Label1.Text = "You did not specify any files to upload or " +
"the file(s) could not be found.";
}

}
[/script]

[html ]
[head runat="server"]
[title]HttpFileCollection Example[/title]
[/head]
[body]
[form id="form1"
runat="server"]
[div]
[asp:FileUpload ID="FileUpload1"
runat="server" /]
[br /]
[asp:FileUpload ID="FileUpload2"
runat="server" /]
[br /]
[asp:Button ID="Button1"
runat="server"
OnClick="Button1_Click"
Text="Upload" /]
[br /]
[asp:Label ID="Label1"
runat="server"/]
[br /]
[asp:BulletedList ID="BulletedList1"
runat="server"]
[/asp:BulletedList]
[/div]
[/form]
[/body]
[/html]



What is the difference between using "String" and "string" ("Object" vs "object"
etc.)?


An object of type "String" in C# is an object of type "System.String", and it's bound that way by the compiler if you use a "using System" directive, like so:

using System;
...
String s = "Hi";
Console.WriteLine(s);

If you were to remove the "using System" statement, I'd have to write the code more explicitly, like so:

System.String s = "Hi";
System.Console.WriteLine(s);

On the other hand, if you use the "string" type in C#, you could skip the "using System" directive and the namespace prefix:

string s = "Hi";
System.Console.WriteLine(s);

The reason that this works and the reason that "object", "int", etc in C# all work is because they're language-specific aliases to underlying .NET Framework types. Most languages have their own aliases that serve as a short-cut and a bridge to the .NET types that existing programmers in those languages understand.

Personally, I prefer to use the aliases instead of the .NET versions because, as an old-time C/C++ programmer, I prefer to type "int" instead of "Int32" etc. However, both are exactly equivalent, so pick the one you like best and stick with it.






Saturday, March 15, 2008

How to show texl of a control in two colors

lnkFriendRequest.Text = " Friend Requests " + ViewState["count_request"].ToString() + " new";
output is as folows
Friend Requests (o new)
Mahesh K. Sharma
mahesh.sharma@live.in

how to show link buton text in two colors

lnkFriendRequest.Text = " Friend Requests " + ViewState["count_request"].ToString() + " new";
output is as folows
Friend Requests (o new)
Mahesh K. Sharma
mahesh.sharma@live.in