Search This Blog

Friday, September 16, 2011

AS per twitter Focus -in -out and watermark through javascript



 <style type="text/css">
      
        .tb
        {
           background-image:url(textbox_signup.png);
            background-repeat:no-repeat;
            background-position:center;
            width:304px;
            height:38px;
            border:0px;
            background-color:transparent;
            display:block;
            clear:both;
            padding-left:10px
           
        }
       .watermarkOn
        {
         text-align:left;
         color: #000000;
         font-size:medium;
         font-style:normal;
        
        font-family: Verdana,Arial,Helvetica,sans-serif;
        font-size: 13px;
      
       padding-left:10px
        }
       
     
    style>


     <%----%>
  <%----%>
    <script src="js/jquery/jquery-1.6.3.min.js" type="text/javascript">script>

 <script type="text/javascript">
     $(document).ready(function () {


         //User ID Focus -in -out

         $("#txtuserid").focusin(function () {
             $("#txtuserid").css({ 'border-color': 'rgba(82, 168, 236, 0.75)', 'box-shadow': ' 0 0 8px rgba(82, 168, 236, 0.5)', 'color': '#747170'
             });
         });
         $("#txtuserid").focusout(function () {
             $("#txtuserid").css({ 'box-shadow': 'none', 'color': '#000000' });
         });


         // Password Focus -in -out

         $("#txtpassword").focusin(function () {
             if ($(this).val() == "" || $(this).val() == "Password") {
                 document.getElementById('txtpassword').type = 'text';
             }
             else {
                 document.getElementById('txtpassword').type = 'password';
             };
             $("#txtpassword").css({ 'border-color': 'rgba(82, 168, 236, 0.75)', 'box-shadow': ' 0 0 8px rgba(82, 168, 236, 0.5)', 'color': '#747170' });
         });

         $("#txtpassword").focusout(function () {
             $("#txtpassword").css({ 'box-shadow': 'none', 'color': '#000000' });
         });


         //Username -Keypress -blur event*************************************************************

        


         //For User ID

         $("#txtuserid").keypress(function () {
              $(this).filter(function () {

                  return $(this).val() == "" || $(this).val() == "User Id"

             }).removeClass("watermarkOn").val("");

          }).addClass("watermarkOn").val("User Id");

         $("#txtuserid").blur(function () {
            $(this).filter(function () {
                 return $(this).val() == ""

             }).addClass("watermarkOn").val("User Id");

         });

         //For Password

         $("#txtpassword").keypress(function () {
             document.getElementById('txtpassword').type = 'password';
             $(this).filter(function () {

                 return $(this).val() == "" || $(this).val() == "Password"

             }).removeClass("watermarkOn").val("");

         }).addClass("watermarkOn").val("Password");

         $("#txtpassword").blur(function () {
             if ($(this).val() == "") {
                 document.getElementById('txtpassword').type = 'text';
             };
             $(this).filter(function () {
                 return $(this).val() == ""

             }).addClass("watermarkOn").val("Password");

         });
        
     });
script>
*------------------------ in aspx-----------------------------
       <asp:TextBox ID="txtuserid" runat="server" Text="User Id" class="loginbox">asp:TextBox>
                    
<asp:TextBox ID="txtpassword" runat="server" Text="Password" class="loginbox" >asp:TextBox>

Tuesday, September 13, 2011

31 Tips on ASP.NET, C#, WPF , MEF, MVC, Visual Studio

Daily .NET Tips is aiming to sharing useful coding tips and tricks for .NET Developers. This site completely design for sharing Tips and Tricks, useful Code Snippet which anyone use in daily development work and targeted anything related with .NET.   This month we have wide range of tips including Threading, MEF, WPF and MVC. In this post I am quickly listing down all the tips which are published over the month August 2011

  1. Working with AggregateCatalog in MEF
  2.  Working with DirectoryCatalog in MEF
  3. Working with AssemblyCatalog in MEF
  4. Working with TypeCatalog in MEF
  5. How to use DebuggerTypeProxy while debugging your sensitive Type
  6. ASP.NET Calendar Control as Outlook Calendar
  7. Initialize assemblies using PreApplicationStartMethod for ASP.NET 4.0 Application
  8. Async Lambda Expression
  9. Playing with ASP.NET List Controls using jQuery
  10. How to allow user to input html in ASP.NET MVC?
  11. Using Mutex to avoid deadlocks
  12. Writing inline Code in WPF
  13. What is SynchronizationContext all about
  14. ThreadLocal storage in .NET
  15. Barrier in .NET 4.0
  16. Use of Interlocked in Race Condition
  17. Call ASP.NET Page Methods using your own AJAX
  18. Use of SpinLock for ThreadLocking
  19. Using ReaderWriterLock over Monitor for Thread Locking
  20. What is the use of IsBackground property of Thread?
  21. Enable Address Level Debugging in Visual Studio
  22. Get List of all Control Types in WPF
  23. How to apply simple faded transparent effects on WPF controls ?
  24.  Use Visual Studio Server Explorer to Add New or Existing SQL Server CE Database
  25. Co-Ordinated Thread Shutdown with and without using CancellationTokenSource
  26. Generate thousand of request
  27. Writing a Stretchable ContentControl in WPF
  28. How to Retrieve WPF Visual Tree Programmatically ?
  29. What is Visual Tree and Logical Tree in WPF?
  30.  Dealing with HWND in WPF
  31. Hosting a WPF control inside a Windows Form

Thursday, September 8, 2011

Changes to Browser Capabilities

ASP.NET determines the capabilities of the browser that a user is using to browse your site by using a feature called browser capabilities. Browser capabilities are represented by the HttpBrowserCapabilities object (exposed by the Request.Browser property). For example, you can use the HttpBrowserCapabilities object to determine whether the type and version of the current browser supports a particular version of JavaScript. Or, you can use the HttpBrowserCapabilities object to determine whether the request originated from a mobile device.
The HttpBrowserCapabilities object is driven by a set of browser definition files. These files contain information about the capabilities of particular browsers. In ASP.NET 4, these browser definition files have been updated to contain information about recently introduced browsers and devices such as Google Chrome, Research in Motion BlackBerry smartphones, and Apple iPhone.
The following list shows new browser definition files: blackberry.browser chrome.browser Default.browser firefox.browser gateway.browser
generic.browser ie.browser iemobile.browser iphone.browser opera.browser safari.browser
Using Browser Capabilities Providers
In ASP.NET version 3.5 Service Pack 1, you can define the capabilities that a browser has in the following ways: At the computer level, you create or update a .browser XML file in the following folder:
\Windows\Microsoft.NET\Framework\v2.0.50727\CONFIG\Browsers
After you define the browser capability, you run the following command from the Visual Studio Command Prompt in order to rebuild the browser capabilities assembly and add it to the GAC:
aspnet_regbrowsers.exe –I c For an individual application, you create a .browser file in the application’s App_Browsers folder.
These approaches require you to change XML files, and for computer-level changes, you must restart the application after you run the aspnet_regbrowsers.exe process.
ASP.NET 4 includes a feature referred to as browser capabilities providers. As the name suggests, this lets you build a provider that in turn lets you use your own code to determine browser capabilities.
In practice, developers often do not define custom browser capabilities. Browser files are hard to update, the process for updating them is fairly complicated, and the XML syntax for .browser files can be complex to use and define. What would make this process much easier is if there were a common browser definition syntax, or a database that contained up-to-date browser definitions, or even a Web service for such a database. The new browser capabilities providers feature makes these scenarios possible and practical for third-party developers.
There are two main approaches for using the new ASP.NET 4 browser capabilities provider feature: extending the ASP.NET browser capabilities definition functionality, or totally replacing it. The following sections describe first how to replace the functionality, and then how to extend it.
Replacing the ASP.NET Browser Capabilities Functionality
To replace the ASP.NET browser capabilities definition functionality completely, follow these steps:
1. Create a provider class that derives from HttpCapabilitiesProvider and that overrides the GetBrowserCapabilities method, as in the following example:
public class CustomProvider : HttpCapabilitiesProvider
{
public override HttpBrowserCapabilities
GetBrowserCapabilities(HttpRequest request)
{
HttpBrowserCapabilities browserCaps = new HttpBrowserCapabilities();
Hashtable values = new Hashtable(180, StringComparer.OrdinalIgnoreCase);
values[String.Empty] = request.UserAgent;
values["browser"] = "MyCustomBrowser";
browserCaps.Capabilities = values;
return browserCaps;
}
}
The code in this example creates a new HttpBrowserCapabilities object, specifying only the capability named browser and setting that capability to MyCustomBrowser.
2. Register the provider with the application.
In order to use a provider with an application, you must add the provider attribute to the browserCaps section in the Web.config or Machine.config files. (You can also define the provider attributes in a location element for specific directories in application, such as in a folder for a specific mobile device.) The following example shows how to set the provider attribute in a configuration file:



Another way to register the new browser capability definition is to use code, as shown in the following example:
void Application_Start(object sender, EventArgs e)
{
HttpCapabilitiesBase.BrowserCapabilitiesProvider =
new ClassLibrary2.CustomProvider();
// ...
}
This code must run in the Application_Start event of the Global.asax file. Any change to the BrowserCapabilitiesProvider class must occur before any code in the application executes, in order to make sure that the cache remains in a valid state for the resolved HttpCapabilitiesBase object.
Caching the HttpBrowserCapabilities Object
The preceding example has one problem, which is that the code would run each time the custom provider is invoked in order to get the HttpBrowserCapabilities object. This can happen multiple times during each request. In the example, the code for the provider does not do much. However, if the code in your custom provider performs significant work in order to get the HttpBrowserCapabilities object, this can affect performance. To prevent this from happening, you can cache the HttpBrowserCapabilities object. Follow these steps:
1. Create a class that derives from HttpCapabilitiesProvider, like the one in the following example:
public class CustomProvider : HttpCapabilitiesProvider
{
public override HttpBrowserCapabilities
GetBrowserCapabilities(HttpRequest request)
{
string cacheKey = BuildCacheKey();
int cacheTime = GetCacheTime();
HttpBrowserCapabilities browserCaps =
HttpContext.Current.Cache[cacheKey] as
HttpBrowserCapabilities;
if (browserCaps == null)
{
HttpBrowserCapabilities browserCaps = new
HttpBrowserCapabilities();
Hashtable values = new Hashtable(180,
StringComparer.OrdinalIgnoreCase);
values[String.Empty] = request.UserAgent;
values["browser"] = "MyCustomBrowser";
browserCaps.Capabilities = values;
HttpContext.Current.Cache.Insert(cacheKey,
browserCaps, null, DateTime.MaxValue,
TimeSpan.FromSeconds(cacheTime));
ASP.NET 4 and Visual Studio 2010 Web Development Overview 23
© 2010 Microsoft Corporation
}
return browserCaps;
}
}
In the example, the code generates a cache key by calling a custom BuildCacheKey method, and it gets the length of time to cache by calling a custom GetCacheTime method. The code then adds the resolved HttpBrowserCapabilities object to the cache. The object can be retrieved from the cache and reused on subsequent requests that make use of the custom provider.
2. Register the provider with the application as described in the preceding procedure.
Extending ASP.NET Browser Capabilities Functionality
The previous section described how to create a new HttpBrowserCapabilities object in ASP.NET 4. You can also extend the ASP.NET browser capabilities functionality by adding new browser capabilities definitions to those that are already in ASP.NET. You can do this without using the XML browser definitions. The following procedure shows how.
1. Create a class that derives from HttpCapabilitiesEvaluator and that overrides the GetBrowserCapabilities method, as shown in the following example:
public class CustomProvider : HttpCapabilitiesEvaluator
{
public override HttpBrowserCapabilities
GetBrowserCapabilities(HttpRequest request)
{
HttpBrowserCapabilities browserCaps =
base.GetHttpBrowserCapabilities(request);
if (browserCaps.Browser == "Unknown")
{
browserCaps = MyBrowserCapabilitiesEvaulator(request);
}
return browserCaps;
}
}
This code first uses the ASP.NET browser capabilities functionality to try to identify the browser. However, if no browser is identified based on the information defined in the request (that is, if the Browser property of the HttpBrowserCapabilities object is the string “Unknown”), the code calls the custom provider (MyBrowserCapabilitiesEvaluator) to identify the browser.
2. Register the provider with the application as described in the previous example.
Extending Browser Capabilities Functionality by Adding New Capabilities to Existing Capabilities Definitions
In addition to creating a custom browser definition provider and to dynamically creating new browser definitions, you can extend existing browser definitions with additional capabilities. This lets you use a definition that is close to what you want but lacks only a few capabilities. To do this, use the following steps.
1. Create a class that derives from HttpCapabilitiesEvaluator and that overrides the GetBrowserCapabilities method, as shown in the following example:
public class CustomProvider : HttpCapabilitiesEvaluator
{
public override HttpBrowserCapabilities
GetBrowserCapabilities(HttpRequest request)
{
HttpBrowserCapabilities browserCaps =
base.GetHttpBrowserCapabilities(request);
browserCaps.Frames = true;
browserCaps.Capabilities["MultiTouch"] = "true";
return browserCaps;
}
}
The example code extends the existing ASP.NET HttpCapabilitiesEvaluator class and gets the HttpBrowserCapabilities object that matches the current request definition by using the following code:
HttpBrowserCapabilities browserCaps =
base.GetHttpBrowserCapabilities(request);
The code can then add or modify a capability for this browser. There are two ways to specify a new browser capability: Add a key/value pair to the IDictionary object that is exposed by the Capabilities property of the HttpCapabilitiesBase object. In the previous example, the code adds a capability named MultiTouch with a value of true.
Set existing properties of the HttpCapabilitiesBase object. In the previous example, the code sets the Frames property to true. This property is simply an accessor for the IDictionary object that is exposed by the Capabilities property.
Note This model applies to any property of HttpBrowserCapabilities, including control adapters.
2. Register the provider with the application as described in the earlier procedure.