Calling a c# methode from javascript/jquery and get the result
<p>I have a dialog in an ASP.Net,c# application.This dialog has a textbox.When I choose save I want to call a function from C# who makes some verifications in the database and then to get the result in javascript/jquery.If the inserted value is true I want to close the dialog other way to remain opened,but I can't succed to close the dialog box after i receive true from c# function.Below is the code:</p>

<p>ascx :</p>

<pre><code>    &lt;div id="popup" title="Choose Delegate"&gt;
        &lt;label&gt;Delegate&lt;label&gt;&lt;input type="textbox" value="" name="inputD" id=="inputD"/&gt;
     &lt;/div&gt;
</code></pre>

<p>Javascript:</p>

<pre><code>$('#btnAdd').click(function(e){
$('#divPopup').slow("show");
$('#divPopup').dialog({
      height:150,
      width:300,
      modal:true,
      buttons:{
               "close":function(){$(this).dialog("close");}
               "save":function(){
                  var obj=document.getElementid("inputD");

                  $.ajax({
                    type: "POST",
                    url: "add.aspx/check",
                    data: "{delegate: '" + obj.Value+"'}",
                    contentType: "application/json; charset=utf-8", 
                    dataType: "json",
                    success: function (msg) {
                          rez= "OK";
                          $(this).dialog("close");
                         },
                    failure: function () {alert("FAIL"); }});                    }
        });
      }
</code></pre>

<p>C#:</p>

<pre><code>[WebMethode]
public static Boolean check(string delegate)
{
   .....

   return true;

  }
</code></pre>

<p>C# methode returns corect value.</p>

<p>I try also this :</p>

<pre><code>       $('#btnAdd').click(function(e){

           $('#divPopup').slow("show");
           $('#divPopup').dialog({
                       height:150,
                       width:300,
                       modal:true,
                       buttons:{
             "close":function(){$(this).dialog("close");}

            "save":function(){
                  var obj=document.getElementid("inputD");
                  var rez ;

                  $.ajax({
                    type: "POST",
                    url: "add.aspx/check",
                    data: "{delegate: '" + obj.Value+"'}",
                    contentType: "application/json; charset=utf-8", 
                    dataType: "json",
                    success: function (msg) {
                          rez= "OK";
                                                       },
                    failure: function () {alert("FAIL"); }
                 });       

                    if (rez="OK")
                          $(this).dialog("close");

         }
        });
</code></pre>

<p>But it doesn't see the rez value in this case.</p>

<p>Thanks !</p>
