A New Internet Library: Add Your Website/Blog or Suggest A Website/Blog to our Free Web Directory http://anil.myfunda.net.

Its very simple, free and SEO Friendly.
Submit Now....

Thursday, July 24, 2008

Cross Page Post Back Labels: ASP.NET 2.0

ASP.Net 1.1 provides for web forms posting back only to themselves. In many situations, the solution requires posting to a different web page. The traditional workaround alternatives were to use Response.Redirect and/or Server.Transfer to move to a different page and simulate cross page post-back behavior.

 

ASP.Net 2.0 provides a feature known as Cross Page PostBack for a web form to post-back to a different web form (other than itself)

 

How to post to a different page

 

To set a web form to post back to a different web form, in the source web form, set the PostBackURL property of a control that implements IButtonControl (eg. Button, ImageButton, LinkButton) to the target web form. When the user clicks on this button control, the web form is cross-posted to the target web form. No other settings or code is required in the source web form.

 

Access source page info within the posted page: FindControl Method

 

The target web form resulting from the cross-page postback provides a non-null PreviousPage property. This property represents the source page and provides reference to the source web form and its controls.

 

The controls on the source page can be accessed via the FindControl method on the object returned by the PreviousPage property of the target page.

 

protected void Page_Load(object sender, EventArgs e)

{

    ...

    TextBox txtStartDate = (TextBox) PreviousPage.FindControl("txtStartDate ");

    ...

}

 

At this point the target page does not have any knowledge of the source page. The PreviousPage property is of the type Page. For accessing controls using FindControl, the developer has to presume a certain structure in the source web form. This approach using FindControl has a few limitations. FindControl is dependent on the developer to provide the ids of the controls to access. The code will stop working if the control id is changed in the source web form. The FindControl method can retrieve controls only within the current container. If you need to access a control within another control, you need to first get a reference to the parent control.

 

Access source page info within the posted page: @PreviousPageType Directive

 

There is another more direct option to get access to the source page controls if the source page is pre-determined. The @PreviousPageType directive can be used in the target page to strongly type the source page. The directive specifies the source page using either the VirtualPath attribute or the TypeName attribute. The PreviousPage property then returns a strongly typed reference to the source page. It allows access to the public properties of the source page.

 

SourcePage.aspx:

 

<form runat="server" >
...
<asp:textbox runat="server" id
="txtFirstName"/>
<
asp:textbox runat="server" id
="txtLastName"/>
<
asp:button runat="server" id="btnViewReport" Text="View Report" PostbackURL="~/targetpage.aspx"
/>
...

public string FirstName

{

    get { return txtFirstName.Text; }

}

...

 

TargetPage.aspx

 

<%@ PreviousPageType VirtualPath="sourcepage.aspx" %>

string strFirstName;
strFirstName = PreviousPage.FirstName
//Strongly Typed PreviousPage allows direct access to the public properties of the source page.

Access source page info within the posted page: @Reference Directive

 

A third option to access the source page in a strongly typed fashion from the target page is to include an @Reference directive to the source page in the target page and then cast the PreviousPage property to the type of the source page.

 

Detect Cross Page PostBacks: IsCrossPagePostBack Property

 

When the source page cross-posts back to the target page, and the target page accesses the source page, the source page is reloaded in memory and goes through all the life cycle stages except the rendering. This version of the source page object is used by the target page to access information on the source page.

 

The IsCrossPagePostBack property in the source page indicates if it is being reloaded in memory in response to a PreviousPage reference from a target page.

  1. Page A cross postback to Page B
  2. Page B accesses the PreviousPage : Page A is reloaded in memory and the IsCrossPostBack property on this object has the value "true".

The IsCrossPagePostBack property can be used in the source page to prevent un-necessary processing from repeating when the page is being reloaded for the PreviousPage reference.

The PreviousPage.IsCrossPagePostBack property can be used to deduce if the current page has been loaded as a result of a cross page postback.

Validations

 

If the Source Page has any Validator controls, the source page will need to have valid input when it has cross posted to the target page. The target page can contain the validation check for PreviousPage.IsValid to catch invalid submissions to the source page.

 

Usage Scenarios

           

Previous limitations restricted the postback to the self page in ASP.Net 1.1. In ASP.Net 2.0, you can use cross-page post backs to post to a different web page, resulting in more intuitive, structured and maintainable code.

 

Example - A web form collects criteria for a web-based report (such as Report Type, Report Start Date and Report End Date) and the form is cross page posted to another web form which generates the report based on the parameters passed in the previous page.

 

A typical use for cross page postback is where you need a page to post to different pages by clicking on different button controls in the same form. The target page is specified with each button control, allowing postbacks to various forms.

 

When posting across applications, cross page postbacks allow access to the posted form data, but do not provide access to the source page's controls and viewstate.

Thursday, July 10, 2008

Mackay's Moral: Nature is full of examples of teamwork. Teamwork should be part of your nature.

Stand together or fall apart
The huge redwood trees in California are considered to be the tallest trees in the world. Some of them are 300 feet high and more than 2,500 years old. One would think that trees so large would have a tremendous root system reaching down hundreds of feet into the earth. Not true. The redwoods actually have a very shallow root system, but they all intertwine. They don't stand alone, for all the trees support and protect each other. When the storms come or the winds blow, the redwoods stand together.
There is strength in numbers.
To drive home the power of teamwork and sticking together, I sometimes do a visual exercise during my speeches to corporate America, as well as in-house for our salesforce and employees. I hold up a bundle of six pencils and try to break them in the air and then over my knee. The average person can't break the bundle. Then I take one pencil out and snap it in two easily. I point out that if you help each other, you will be like the bundle of pencils. No one can break you apart. But if you are divided among yourselves, you will be broken as easily as a single pencil.
It's a hard lesson for us, but unity consistently produces greater results than individual endeavors. Teamwork divides the effort and multiplies the effect.
In a pulling contest at a county fair, the first place horse ended up moving a sled weighing 4,500 pounds. The second place finisher pulled 4,000 pounds. The owners of the two horses decided to see what these horses could pull together. They hitched them up and found that the team could move 12,000 pounds.
By working separately, the two horses were good for only 8,500 pounds. However, when coupled together, their synergism produced an added 3,500 pounds!
And what about the farmer who grew award-winning corn? Each year he entered his corn in the state fair where it won a blue ribbon. One year a newspaper reporter interviewed him and learned something interesting about how he grew it.
The reporter discovered that the farmer shared his seed corn with his neighbors. "How can you afford to share your best seed corn with your neighbors when they are entering corn in competition with yours each year?" the reporter asked.
"Why sir," said the farmer, "did you know that the wind picks up pollen from the ripening corn and swirls it from field to field. If my neighbors grow inferior corn, cross-pollination will steadily degrade the quality of my corn. If I am to grow good corn, I must help my neighbors grow good corn."
June marks my wedding anniversary, so the next story is timely for me. Many years ago in Austria they had a custom that helped villagers size up the future happiness of a newly married couple.
After the wedding in the local church, the village women would escort the bride and groom to a nearby forest and stand them before a large tree. They would then hand the young couple a two-handled bucksaw and ask that they use it to cut the tree down.
The closer the cooperation between the man and wife, the shorter the time it took for the tree to come down. And the older villagers wisely reasoned that, the shorter the time, the happier the young couple would be because they had learned that most valuable of marital lessons—teamwork!
Phil Jackson, the highly successful coach of the Los Angeles Lakers professional basketball team, frequently reads poetry to his players. To inspire his players on the subject of teamwork, he once read the following lines from Kipling's 1895 poem "The Law of the Jungle":
Now this is the Law of the Jungle —
As old and as true as the sky;
And the Wolf that shall keep it may prosper,
But the Wolf that shall break it must die.
As the creeper that girdles the tree-trunk
The Law runneth forward and back —
But the strength of the Pack is the Wolf,
And the strength of the Wolf is the Pack.
Mackay's Moral: Nature is full of examples of teamwork. Teamwork should be part of your nature.

Dynamically loading loading external JavaScript or CSS files in Javascript using DOM object.

To load a .js or .css file dynamically, in a nutshell, it means using DOM methods to first create a swanky new "SCRIPT" or "LINK" element, assign it the appropriate attributes, and finally, use element.appendChild() to add the element to the desired location within the document tree.

function loadjscssfile(filename, filetype){
if (filetype=="js"){ //if filename is a external JavaScript file
var fileref=document.createElement('script')
fileref.setAttribute("type","text/javascript")
fileref.setAttribute("src", filename)
}
else if (filetype=="css"){ //if filename is an external CSS file
var fileref=document.createElement("link")
fileref.setAttribute("rel", "stylesheet")
fileref.setAttribute("type", "text/css")
fileref.setAttribute("href", filename)
}
if (typeof fileref!="undefined")
document.getElementsByTagName("head")[0].appendChild(fileref)
}

loadjscssfile("myscript.js", "js") //dynamically load and add this .js file
loadjscssfile("javascript.php", "js") //dynamically load "javascript.php" as a JavaScript file
loadjscssfile("mystyle.css", "css") ////dynamically load and add this .css file

Wednesday, July 2, 2008

Dotnet-Interviews: Can any one solve this Puzzle / Problem in C#.NET

Dotnet-Interviews: Can any one solve this Puzzle / Problem in C#.NET

Monday, June 30, 2008

How to register or unregister a DLL?

Register or unregister a DLL.

Syntax
REGSVR32 [/U] [/S] [/C] [/I:[Command_Line]] DLL_Name

REGSVR32 [/U] [/S] [/C] /N /I:[Command_Line] DLL_Name
Key

/u Unregister Server.
/s Silent - no dialogue boxes.
/c Console output.
/n Don't call DllRegisterServer
/i Call DllInstall (or DllUninstall if /u is specified)
Command_Line An optional command line for DllInstall
Examples

Unregister (disable) XP Zip folders
REGSVR32 /u C:\Windows\System32\zipfldr.dll

Unregister (Disable) CAB file viewer:
REGSVR32 /u C:\Windows\System32\cabview.dll

Register (enable) XP Zip folders
REGSVR32 zipfldr.dll

Register (enable) CAB file viewer:
REGSVR32 cabview.dll

Register Windows Update DLLs (for those times when XP repair breaks Windows Update)
regsvr32 /s wuapi.dll

Thursday, June 26, 2008

Different class and member Access modifiers / modifiers in C# and VB.NET?


























































C#


VB


Class cannot be inherited (cannot be a base class).


Sealed


NotInheritable


Class cannot be instantiated but only used as based
class and/or with abstract methods.


Abstract


MustInherit


For class members: member is accessible only from the
class in which it is declared. For classes: only allowed on nested classes
to restrict access to the nested class to the containing class..


Private


Private


For class members: member is accessible only from types
defined in the same assembly. For classes: class is accessible only from
types in the same assembly.


Internal


Friend


For members: member is accessible from the class in
which it is declared and from any class derived from that class.


Protected


Protected


Combines the access of Protected and Internal for a
class member


Protected Internal


Protected Friend


Access is not restricted.


Public


Public


Hides a member inherited from a base class.


New


Shadows


Monday, June 2, 2008

Insight of new version of Internet Explorer IE 8

Microsoft has kept development of Internet Explorer 8 pretty quiet, but already the next major version of the most widely-used browser is available for downloading in a beta version.

While the focus of IE 7 was on security and the incorporation of a tabbed interface, version 8's main features center on stability and usability.

In terms of stability, IE 8's new automatic crash recovery feature is designed to solve one major problem that most IE users know all too well. Today, when an IE window or tab freezes or crashes, other browsers instances or tabs will likely become inoperable as well.

Automatic crash recovery does a better job of isolating instances of the IE browser - or separate tabs within the same browser - so that one stalled browser or tab can be terminated without affecting any other.

If a crash does bring down the entire browser, automatic crash recovery will attempt to restore the browser to its previous state - including all open tabs - the next time you open it.

Greater stability is fine - but ultimately boring. Luckily, that's not all IE 8 has going for it. The new browser's usability features will generate the most buzz - and are likely to tempt lots of folks to give IE 8 a try.

The new Activities feature, for instance, attempts to save you a lot of times by cutting down on the number of separate sites that you have to visit to accomplish a task. In essence, the Activities feature allows you to invoke the essential services offered on separate sites without ever leaving the page you're currently on.

Let's say, for example, that you're reading a web page and you see an address for a restaurant you'd like to visit.

Today, in order to get directions to that address, you would probably go to a mapping site and type or paste the address in and then wait for the service to provide you with a map from, say, your apartment to the restaurant.

The process is time-consuming and involves at least two browser windows and tabs, plus a bit of copying a pasting.

With IE 8's Activities feature, when you select the address, a small Activities button appears next to your mouse cursor. Clicking that Activities button brings up a context-sensitive menu of possible activities, with one of the options being the ability to map the tool using your favorite mapping site.

 
Selecting that mapping option actually invokes the mapping site in a smaller preview window inside the current browser tab.


Another Activity might pull from a review site of restaurants, allowing you to see what others have said about the restaurant without your having to visit another site.

 
The Activities feature was also created with a nod toward the growing popularity of social networking sites. Just as you can pull services from other sites, the Activities feature also allows you to push information to popular networking sites such as Facebook and Digg.

 
If you want to refer a friend to the page from which you got the address for the restaurant, for instance, you can select the Send to Facebook option on the Activities menu, and IE 8 will log you into Facebook, send the URL to Facebook, and present you with the Facebook page that allows you to add an entry.

 
A set of default Activities comes with the IE 8 browser, but you easily customise the service providers that appear on your Activities list.

 
Another time-saving feature of IE 8 is called Web Slices, which are designed to allow you to subscribe to frequently-updated portions, or "slices," of certain Web sites.


Instead of spending your time visiting three or four Web sites to get updated information from a portion of each of those sites, you would simply use Web Slices to pull that information into a single location in IE 8.

A site such as eBay, for instance, lends itself to the Web Slices feature.

Say, for instance, that you're running or watching several auctions on eBay. Typically, you would visit eBay multiple times per day to check the status of those auctions.

With Web Slices, you can instead simply subscribe to a section of the auction page by clicking a Web Slice icon that appears when you allow your mouse cursor to hover over a portion of a site that is frequently updated.

Clicking the Web Slice icon adds a new button to a Favorites bar that appears above your browser tabs. Clicking the newly-created Web Slice button on the IE 8 Favorites bar will pull the latest data from your subscribed page and show it to you in a preview window.

You can visit the page itself merely by clicking a link within the preview window.
 

As with Activities, Web Slice-enabled sections of sites must be made available by web site owners themselves. The code for doing so is fairly simple and non-proprietary, however, so it will likely simply be a matter of time before many sites become "IE 8 aware" and users start seeing the Activities and Web Slices icons as they surf their favorite sites.

 Download IE8 beta version here

Dotnet-Interviews