Reset Form using Jquery

11. August 2010

If you have one or more then one form in HTML page. You can reset  the form by calling jquery reset function.

Example

$(document).ready(function() {
// you can reset more then one form by using this function
   $("#reset").click(function() {
     $("form").each(function() {
       this.reset();
     });
   });
 });


Author: Aamir Hasan     औथोर: आमिर हसन       أثر أمير حسن .

ALL, asp.net, JQuery , , , , ,

AddClass and removeClass on moveover on a list using jquery asp.net csharp

28. May 2010

In this article, author try to tell us how to append and remove class on client side using jquery and css style.

Reference:Addclass and removeClass on moveover on a list using jquery asp.net csharp

online demo


Author: Aamir Hasan     औथोर: आमिर हसन       أثر أمير حسن .

ALL, asp.net, CSS, HTML, JQuery , , ,

Adjust Auto Height of Iframe using asp.net JQuery

31. March 2010
My first attempt failed both in Internet Explorer and Firefox, worst in Firefox which announced that iframe.document didn’t have any properties, and in Internet Explorer the div element was placed after the iframe
element not inside intended.To configure this script,first, set the variables inside the script of Step 1 per the comments. As you can see, you can specify more than one iframe on the page in which the
script should dynamically Auto Adjust (resize).where "myframe" is the ID of the IFRAME you wish to load a page into, and "iframe.aspx", the
path to the page on your site to load.But happy to have found myself.

iframe code

  1. Opening tag
  2. iframe page source
  3. height of the iframe
  4. width of the iframe
  5. Non-iframe content (What to display in the users' browser if they are not capable of viewing iframes.)
  6. Closing tag
src Specified the URL of the document to be displayed in the frame.
src="FileName.html"
name Specifies the name of the frame for the purpose of linking and targeting.
name="MyIframe"
width
height
Specifies the width/height of the iframe space in pixels or percentages.
width="200" height="100"
align Aligns the iframe to the left, center, or right side of the page.
align="center"
noresize Kills the visitors ability to resize the iframe borders manually.
noresize="noresize"
scrolling Indicates the ability of a scrollbar to appear (or not) with a value of yes, no, or auto.
scrolling="auto"
frameborder Carries a value of 0 or 1 depending if you want a border to appear around the iframe or not.
frameborder="1"
marginwidth
marginheight
Specifies the width/height of the margin in pixels.
marginwidth="1" marginheight="1"
vspace
hspace
Specifies the verticle/horizontal margin space in pixels.
vspace="1" hspace="1"


Accessing the document inside an iframe

When dealing with inline frames (iframe), it is common to have the need to access the document loaded into the iframe.




Default.aspx Page
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript" src="jquery.js"></script>

</head>
<body>
<form id="form1" runat="server">
<div>
<iframe id="myframe" name="myframe" frameborder="1" scrolling="no" src="Default2.aspx"></iframe>
</div>
</form>
</body>
</html>


Copy Page Javascript function on Default.aspx Page.


//created by Aamir Hasan
//Date April,1 2010
function doIframe() {
o = document.getElementsByTagName('iframe');
for (i = 0; i < o.length; i++) {
setHeight(o[i]);
addEvent(o[i], 'load', doIframe);

}
}

function setHeight(e) {

if (e.contentDocument) {
e.height = e.contentDocument.body.offsetHeight + 35;
} else {
e.height = e.contentWindow.document.body.scrollHeight;
}
}

function addEvent(obj, evType, fn) {
if (obj.addEventListener) {
obj.addEventListener(evType, fn, false);
return true;
} else if (obj.attachEvent) {
var r = obj.attachEvent("on" + evType, fn);
return r;
} else {
return false;
}
}

if (document.getElementById && document.createTextNode) {
addEvent(window, 'load', doIframe);
}

Warning

In order to support the most browsers with the least headaches, it is best to use the highly-compatible "DOM0" frames collection, which is a child of window.

Inlcude jquery.js in your Default.aspx Page

jquery.js (122.64 kb)


Compatibility

This code has been tested on and is known to work in:

  • Internet Explorer 6 (Win), 5.5 (Win)
  • Mozilla 1.7.5 (all) - Firefox 1.0 - Filefox 3.6.2
  • Safari 1.2.4, Safari 3.1.1
  • Opera 7.54 (Win), Opera 9.8 (Win)

Author: Aamir Hasan     औथोर: आमिर हसन       أثر أمير حسن .

Ajax, asp.net, HTML, JQuery , , ,

Calling server side methods to ClientSide using Json, JavaScript and JQuery in ASP.Net csharp

22. January 2010

Autohr: Aamir Hasan

how many time people ask in forum.asp.net and mail to me that how can we get a value from server side to Client side by javscript

so now i have decided to make a tutorial of aspx using csharp

By using jQuery we can send and get value without call back

 

Following rules to be follows are:

1) you have to include jquery library.

2) jquery function

3) create a button and client side function call.

in your aspx page

write this line of code


<div>
Your Name :
<asp:TextBox ID="tbUserName" runat="server"></asp:TextBox>
<input id="btnGetTime" type="button" value="Show Current Time"
    onclick = "ShowServerTime()" />
</div>

Client Side in side the head tag

 


Ajax method will call to server side and get the Current dattime from the server to client side.

 

 

Server side Csharp method.

 

[System.Web.Services.WebMethod]
public static string GetServerTime(string Username)
{
return "Welcome To StudentAcad.com \nThe Server Time is: "
+ DateTime.Now.ToString();
}

Above Method will return the Message with Server datetime

 

Important note: if above Web Method  will not be static then you are un able to call the method.


Author: Aamir Hasan     औथोर: आमिर हसन       أثر أمير حسن .

ALL, asp.net, JQuery , ,

comparing JSON and xml using Web Service returns data

31. December 2009

Web Services, where XML is difficult to process on the client side. Also, XML is larger in size than its corresponding JSON representation. For each property, XML has two tags: opening and closing. On the other hand, JSON has the property name only once.JSON is a lightweight data-interchange format. Like XML, it is human-readable, platform independent, and enjoys a wide availability of implementations. JSON is a subset of the object literal notation of JavaScript. Data represented in JSON can be parsed by JavaScript easily, so it is ideal for AJAX based web applications. For your information, JSON does not have any support for datetime as JavaScript doesn't have its own datetime data type. Rather, datetime in JavaScript is an object. You can read here details on how JSON datetime is handled in AJAX.

 

If a Web Service returns XML data, then the data to be passed from the server to the client is larger than what it would be in the case of JSON. So, using JSON, we only need to pass fewer amounts of data. Also, XML parsing on client side is cumbersome and costly in the perspective of processing. If there’s another easier way, then why should not we use that? Let’s assume the following XML data is returned by the Web Service.



<Employee>
<EmpID>100</EmpID>
<Name>Aamir Hasan</Name>
<Address>Studentacad.com</Address>
</Employee>



To parse data on the client-side, you’ll need to use JavaScript XML features.

On the other hand, if the Web Service returns JSON format, then the same data is represented as:



{"EmpID":100,"Name":Aamir Hasan,"Address": Studentacad.com}


 

 

we can see that the JSON representation is much smaller in size than its equivalent XML representation. Also, we’ll see later how easy it is to parse JSON formatted data. 


Define JSON serializer  in web.config


he JSON serializer described later is only supported in .NET framework 3.5

<section name="jsonSerialization"
type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions,
Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
requirePermission="false" allowDefinition="Everywhere"/>

 

 


By default, the ScriptJsonSerializer limits the JSON string to a length of 102400 (UTF-8) characters.
If you need to change the maximum length of the JSON string, then change the maxJsonLenght property of JsonSerialization.
In the section shown below, the max length is changed to 80000 characters:


<configuration>
<system.web.extensions>
<scripting>
<webServices>
<jsonSerialization maxJsonLength="80000"/>
</webServices>
</scripting>
</system.web.extensions>
</configuration>

 

Make the object serializable


[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string GetProductsJson(string prefix)
{
List<Product> products = new List<Product>();
if (prefix.Trim().Equals(string.Empty, StringComparison.OrdinalIgnoreCase))
{
products = ProductFacade.GetAllProducts();
}
else
{
products = ProductFacade.GetProducts(prefix);
}
//yourobject is your actula object (may be collection) you want to serialize to json
DataContractJsonSerializer serializer = new DataContractJsonSerializer(products.GetType());
//create a memory stream
MemoryStream ms = new MemoryStream();
//serialize the object to memory stream
serializer.WriteObject(ms, products);
//convert the serizlized object to string
string jsonString = Encoding.Default.GetString(ms.ToArray());
//close the memory stream
ms.Close();
return jsonString;

Original Content

 

http://www.codeproject.com/KB/webservices/JsonWebServiceJQuery.aspx 

 

 

 


Author: Aamir Hasan     औथोर: आमिर हसन       أثر أمير حسن .

Ajax, ALL, asp.net, Javascript, JQuery , , , ,



User Name: Guest

Your Ip: 38.107.191.93
Time: