call web service from javascript:
1. write a web methord in asmx file.
2. include namespace :
using System.Web.Script.Services;
3. add attribute [ScriptService] to class of web service
example:
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ToolboxItem(false)]
[ScriptService] //-- this is very important
public class DemoService : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld( string yourname)
{
return "Hello World" + yourname;
;
}
}
4. Open Default.aspx in design view and select the ScriptManager1
Select the "Services" property, and click the button that appears
Click "Add", and enter "DemoService.asmx" for the path property
Click OK. The result should look like this:
example:
<asp:scriptmanager id="ScriptManager1" runat="server">
<services>
<asp:servicereference path="DemoService.asmx">
</services>
</asp:ScriptManager>
5.Open Default.aspx in source view and enter just before the "head" tag the following code:
<script type="text/javascript">
function CallService()
{
WebServiceDemo.DemoService.HelloWorld( "Yourself",Callback );
}
function Callback( result )
{
var outDiv = document.getElementById("outputDiv");
outDiv.innerText = result;
}
</script>
6. Create a button to start the web service calling function
Drag a button onto the form
Set the property "OnClientClick" to "CallService();return false;"
7.Create div for the output data
Drag a div (from the HTML tab) onto the form.
Set its id to "outputDiv";
Wednesday, August 26, 2009
Monday, August 24, 2009
Indian Mobile Phone Validators
Regular expression for Indian mobile phone.
Expression1 :
^((\+){0,1}91(\s){0,1}(\-){0,1}(\s){0,1}){0,1}9[0-9](\s){0,1}(\-){0,1}(\s){0,1}[1-9]{1}[0-9]{7}$
Matches: 9836193498 +919836193498 9745622222
Non-Matches +9197456222222 8745622222 9836193481
Expression2:
^([9]{1})([234789]{1})([0-9]{8})$
Matches: 9881060153
Non-Matches +9197456222222 8745622222 45343241342
Regular expression for Indian mobile phone.
Expression1 :
^((\+){0,1}91(\s){0,1}(\-){0,1}(\s){0,1}){0,1}9[0-9](\s){0,1}(\-){0,1}(\s){0,1}[1-9]{1}[0-9]{7}$
Matches: 9836193498 +919836193498 9745622222
Non-Matches +9197456222222 8745622222 9836193481
Expression2:
^([9]{1})([234789]{1})([0-9]{8})$
Matches: 9881060153
Non-Matches +9197456222222 8745622222 45343241342
Monday, August 3, 2009
Masked edit validator and extender demo
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<cc1:MaskedEditValidator
ID="MaskedEditValidator1"
runat="server"
ControlToValidate="TextBox1"
EmptyValueMessage="Please enter Date of Birth"
InvalidValueMessage="Date is Invalid"
ControlExtender="MaskedEditExtender1"
IsValidEmpty="False"
TooltipMessage="Date is invalid"
Display="Dynamic"/>
<cc1:MaskedEditExtender
ID="MaskedEditExtender1"
runat="server"
Mask='99/99/9999'
MaskType="Date"
TargetControlID="TextBox1"
PromptCharacter="_" />
Regular expression for Date of birth in DD/MM/YYYY
use regular expression validator of Asp.net
and write it exression as
:
^(((0[1-9]|[12]\d|3[01])\/(0[13578]|1[02])\/((19|[2-9]\d)\d{2}))|((0[1-9]|[12]\d|30)\/(0[13456789]|1[012])\/((19|[2-9]\d)\d{2}))|((0[1-9]|1\d|2[0-8])\/02\/((19|[2-9]\d)\d{2}))|(29\/02\/((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))))$
and write it exression as
:
^(((0[1-9]|[12]\d|3[01])\/(0[13578]|1[02])\/((19|[2-9]\d)\d{2}))|((0[1-9]|[12]\d|30)\/(0[13456789]|1[012])\/((19|[2-9]\d)\d{2}))|((0[1-9]|1\d|2[0-8])\/02\/((19|[2-9]\d)\d{2}))|(29\/02\/((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))))$
Subscribe to:
Posts (Atom)