How to get the value of a CSS property using jQuery?
Consider the following HTML:
- <div id="jjTechSol" style="height: 50px;width: 50px;">
- <p>Content</p>
- </div>
- <script type="text/javascript">
- $(document).ready(function () {
alert('Height:'+$("#jjTechSol").css('height')); - alert('Width:'+$("#jjTechSol").css('width'));
}); - </script>
propertyName
Type: String
A CSS property.
How to Compare two fields with jQuery validate plugin?
Consider the following HTML.
- <input type="text" id="txtEmail" name="Email" />
- <input type="text" id="txtConfirmEmail" name="ConfirmEmail" />
- $('#myform').validate({
- rules: {
- Email: { required: true },
- ConfirmEmail: { equalTo: '#txtEmail' }
- }
- });
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.
- static string UppercaseFirst(string s)
- {
- // Check for empty string.
- if (string.IsNullOrEmpty(s))
- {
- return string.Empty;
- }
- // Return char and concat substring.
- return char.ToUpper(s[0]) + s.Substring(1);
- }
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.
- string s = "THIS IS MY TEXT RIGHT NOW";
- s = System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(s.ToLower());
- // (or)
- s = System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(s.ToLower());
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.
- bool hasChildren = (Model.ChildrenAsList.Count() > 0);
- if(hasChildren)
- {
- //code
- }
- else
- {
- //code
- }
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;
Namespaces Required:
using System.Xml.XPath;
using umbraco.MacroEngines;
- @functions{
- public List<string> FetchDataTypeItems(int DataTypeNodeID)
- {
- XPathNodeIterator preValueRootElementIterator = umbraco.library.GetPreValues(DataTypeNodeID);
- preValueRootElementIterator.MoveNext();
- XPathNodeIterator preValueIterator = preValueRootElementIterator.Current.SelectChildren("preValue", "");
- List<string> DataTypeListItems = new List<string>();
- while (preValueIterator.MoveNext())
- {
- DataTypeListItems.Add(preValueIterator.Current.Value);
- }
- string[] CommonTerms = DataTypeListItems.ToArray();
- return DataTypeListItems;
- }
- }
How to get the URL of the current page
The following code is used to get the URL of the current page.
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
OUTPUT
- string url = HttpContext.Current.Request.Url.AbsoluteUri;
- // http://localhost:1302/TESTERS/Default6.aspx
- string path = HttpContext.Current.Request.Url.AbsolutePath;
- // /TESTERS/Default6.aspx
- string host = HttpContext.Current.Request.Url.Host;
- // 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
- Response.Write("<br/> " + HttpContext.Current.Request.Url.Host);
- Response.Write("<br/> " + HttpContext.Current.Request.Url.Authority);
- Response.Write("<br/> " + HttpContext.Current.Request.Url.AbsolutePath);
- Response.Write("<br/> " + HttpContext.Current.Request.ApplicationPath);
- Response.Write("<br/> " + HttpContext.Current.Request.Url.AbsoluteUri);
- Response.Write("<br/> " + HttpContext.Current.Request.Url.PathAndQuery);
OUTPUT
- localhost
- localhost:60527
- /WebSite1test/Default2.aspx
- /WebSite1test
- http://localhost:60527/WebSite1test/Default2.aspx?QueryString1=1&QuerrString2=2
- /WebSite1test/Default2.aspx?QueryString1=1&QuerrString2=2