STEP ONE.

lets create our XML Web Service

[WebMethod]
public string Check(string key)
{
return "your key is " + key;
}

you will notice in the webservice.cs file a line of code with a comment
above it looks somthing like
[Webservice.scripts....]

un-comment that line to allow external script access

STEP 2. create an ajax function
$.ajax({  type: "POST", // use method POST
  url: "MyWebServicePath.asmx/Change", // path to web service
  data: "{'key': ' This is the key' }", // data to post
  contentType: "application/json; charset=utf-8", // content type
  dataType: "json", // data type
  success: function(data) { // on success
     alert(data.d);
  },
  error: function() { // on failure
  // do nothing to prevent application from breaking
  }
  });

from the above what i have done is :

I posted my key string to the web service and i could basiaclly do all my
validation in C# then return the output :)

what I usually do is a return the output from my webservice as an HTML
string so that i can just inject it directly into a div.



On Fri, Jun 12, 2009 at 3:10 PM, Ivar Kunst <iacku...@gmail.com> wrote:

>
>
> Ola,
>
> Thanks for you reply, but im still not there:
>
> My validator:
>
> <script type="text/javascript">
>      $(document).ready(function(){
>        var validator = $("#form_user").validate({
>            onkeyup:false,
>            onblur:false,
>            onclick:false,
>            errorClass: "invalid",
>            errorLabelContainer: $("#errorBox"),
>            wrapper: "p",
>            rules: {
>                m_username: { required: true},
>                m_passw: {required: true},
>            },
>            messages: {
>                m_username: "Please fill in your username",
>                m_passw: "Please fill in your passw."
>           }
>        });
>      });
> </script>
>
> And i have this funtion in the underlying aspx.cs file:
>
> public boolean somefunction()
> {
>      //do a lot of stuff
>      if(everythingIsOk)
>      {
>            return true;
>      }
>      return false;
> }
>
>
> Is there a possibility that i can use the function in the aspx.cs file in
> the validator?
>
> Thanks
>
>
> waseem sabjee wrote:
> >
> > your web service
> >
> > mymethod.asmx.cs
> > [webmethod]
> >
> > public string[] getData() {
> >
> > // note i used a dataset
> > EventsTableAdapters.EventsTableAdapter ta = new
> > EventsTableAdapters.EventsTableAdapter();
> > Events.EventsDataTable dt new Events.EventsDataTable();
> > // C# string list
> > List<string> result as new List<string>();
> >
> > // load data into data table from dataset
> > dt = ta.GetData();
> >
> > // foreach row in table
> > foreach(System.Data.Datarow row in dt.Rows) {
> > // add each row as its own list item
> > result.Add(row["event_title"].ToString());
> >
> > }
> > // return as array
> > return results.ToArray();
> >
> > }
> >
> > default.aspx
> >
> > <script type="text/javascript">
> >  // yes you can integrate asp.net tags within script tags however you
> will
> > not get intelisense
> >
> > // basically i said if the checkbox is checked get and alert the data
> from
> > the web service.
> >
> > $(function() {
> > <% if(CheckBox1.Checked) { %>
> >
> > $.ajax({
> > url:"mymethod.asmx/Getdata",
> > success: function(data) {
> > alert(data);
> > }
> > });
> >
> >
> > <% } %>
> > });
> >
> > </script>
> >
> > On Fri, Jun 5, 2009 at 6:31 PM, Ivar Kunst <iacku...@gmail.com> wrote:
> >
> >>
> >>
> >> Hello all,
> >>
> >> I'm quite new to Jquery, so I need some sort of advice.
> >>
> >> I'm working on a webbased application with a webservice. First it was a
> >> simple html site, but later I started using Jquery. Data is inserted in
> >> some
> >> forms, this I can easily validate through the validator. Now after all
> >> the
> >> data is ok, it's send to the webservice through the C#-code. Some
> >> calculations are being made with the data and a dataset is returned. Now
> >> some errors can occur while doing the calculations. I can't get some
> >> manual
> >> error in the errorbox of the validator.
> >>
> >> Is it possible to let the validator run some c#-function so I can see if
> >> the
> >> data is correct? Or can I set a unvisible checkbox to true/false through
> >> the
> >> c#-code so the validator check this box? A problem with both is, that
> the
> >> validator runs when I click on the "Next"-button. After the validaton,
> >> the
> >> function starts, so if I set the checkbox to false, the validator won't
> >> even
> >> notice.
> >>
> >> Anyone knows a handy approach for this?
> >>
> >> Grt,
> >> Ivar
> >> --
> >> View this message in context:
> >>
> http://www.nabble.com/Calling-C--function-in-the-validator-tp23891455s27240p23891455.html
> >> Sent from the jQuery General Discussion mailing list archive at
> >> Nabble.com.
> >>
> >>
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/Calling-C--function-in-the-validator-tp23891455s27240p23998567.html
> Sent from the jQuery General Discussion mailing list archive at Nabble.com.
>
>

Reply via email to