How to get the value of a CSS property using jQuery?

Consider the following HTML:
  1. <div id="jjTechSol" style="height: 50px;width: 50px;">
  2.  <p>Content</p>
  3.  </div>
The following jQuery is used to get the value of a CSS property.
  1. <script type="text/javascript">
  2. $(document).ready(function () {
           alert('Height:'+$("#jjTechSol").css('height'));
  3.        alert('Width:'+$("#jjTechSol").css('width'));
    });
  4. </script> 
.css( propertyName ) gets the value of style properties for the first element in the set of matched elements.
     propertyName
     Type: String    
     A CSS property.
Wednesday, 15 January 2014
Posted by Jebastin
Tag : ,

How to Compare two fields with jQuery validate plugin?


Consider the following HTML.
  1. <input type="text" id="txtEmail" name="Email"  />
  2. <input type="text" id="txtConfirmEmail" name="ConfirmEmail" /> 
The following script is used to Compare two fields with jQuery validate plugin.
  1. $('#myform').validate({
  2.     rules: {
  3.         Email: { required: true },
  4.         ConfirmEmail: { equalTo: '#txtEmail' }
  5.     }
  6. });
Wednesday, 8 January 2014
Posted by Jebastin

How to convert the first character of a string into upper case?

The following C# code is used to convert the first character of a string into upper case.
  1. static string UppercaseFirst(string s)
  2. {
  3. // Check for empty string.
  4. if (string.IsNullOrEmpty(s))
  5. {
  6.     return string.Empty;
  7. }
  8. // Return char and concat substring.
  9. return char.ToUpper(s[0]) + s.Substring(1);
  10. }
Tuesday, 7 January 2014
Posted by Jebastin
Tag :

How to convert all first letters of a sentence into upper case and rest of the letters into lower case?

The following C# code is used to convert all first letters of a sentence into upper case and rest of the letters into lower case.
  1. string s = "THIS IS MY TEXT RIGHT NOW";
  2. s = System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(s.ToLower());
  3. // (or)
  4. s = System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(s.ToLower());
Posted by Jebastin
Tag :

How to check whether an Umbraco Node has children or not?

The following Razor code is used to check whether an Umbraco Node has children or not.
  1. bool hasChildren = (Model.ChildrenAsList.Count() > 0);
  2. if(hasChildren)
  3. {
  4.     //code
  5. }
  6. else
  7. {
  8.     //code  
  9. }
Posted by Jebastin

Razor function to fetch the Data Type Items in Umbraco

The following Razor function is used to fetch the Data Type Items in Umbraco.

Namespaces Required:
using System.Xml.XPath;
using umbraco.MacroEngines;
  1. @functions{
  2.     public List<string> FetchDataTypeItems(int DataTypeNodeID)
  3.     {
  4.         XPathNodeIterator preValueRootElementIterator = umbraco.library.GetPreValues(DataTypeNodeID);
  5.         preValueRootElementIterator.MoveNext();
  6.         XPathNodeIterator preValueIterator = preValueRootElementIterator.Current.SelectChildren("preValue", "");
  7.         List<string> DataTypeListItems = new List<string>();
  8.         while (preValueIterator.MoveNext())
  9.         {
  10.             DataTypeListItems.Add(preValueIterator.Current.Value);
  11.         }
  12.         string[] CommonTerms = DataTypeListItems.ToArray();
  13.         return DataTypeListItems;
  14.     }
  15. }
Monday, 6 January 2014
Posted by Jebastin

How to get the URL of the current page

The following code is used to get the URL of the current page.

  1. string url = HttpContext.Current.Request.Url.AbsoluteUri;
  2. // http://localhost:1302/TESTERS/Default6.aspx

  1. string path = HttpContext.Current.Request.Url.AbsolutePath;
  2. // /TESTERS/Default6.aspx

  1. string host = HttpContext.Current.Request.Url.Host;
  2. // localhost

You may need to get different values from URL.

Below example shows different ways of extracting different parts of URL

EXAMPLE (Sample URL)

http://localhost:60527/WebSite1test/Default2.aspx?QueryString1=1&QuerrString2=2

  1. Response.Write("<br/> " + HttpContext.Current.Request.Url.Host);
  2. Response.Write("<br/> " + HttpContext.Current.Request.Url.Authority);
  3. Response.Write("<br/> " + HttpContext.Current.Request.Url.AbsolutePath);
  4. Response.Write("<br/> " + HttpContext.Current.Request.ApplicationPath);
  5. Response.Write("<br/> " + HttpContext.Current.Request.Url.AbsoluteUri);
  6. Response.Write("<br/> " + HttpContext.Current.Request.Url.PathAndQuery);

OUTPUT
  1. localhost
  2. localhost:60527
  3. /WebSite1test/Default2.aspx
  4. /WebSite1test
  5. http://localhost:60527/WebSite1test/Default2.aspx?QueryString1=1&QuerrString2=2
  6. /WebSite1test/Default2.aspx?QueryString1=1&QuerrString2=2
Saturday, 4 January 2014
Posted by Jebastin
Tag :

Link To This Post/Page

Spread The Word

Add this button to your blog:
JJ Technology Solutions

Blog Archive

Trackers

eXTReMe Tracker
facebook

- Copyright © JJ Technology Solutions - Powered by Source Code Solutions -