0

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:

ascx :

    <div id="popup" title="Choose Delegate">
        <label>Delegate<label><input type="textbox" value="" name="inputD" id=="inputD"/>
     </div>

Javascript:

$('#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"); }});                    }
        });
      }

C#:

[WebMethode]
public static Boolean check(string delegate)
{
   .....

   return true;

  }

C# methode returns corect value.

I try also this :

       $('#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");

         }
        });

But it doesn't see the rez value in this case.

Thanks !

0

2 Answers 2

1

You can use an Ajax Call in your "save":function(e) and just check the returned value if true close dialog, else remain opened

Ajax calls are really simple to implement, I let you search that :)

Sign up to request clarification or add additional context in comments.

1 Comment

I solved ,i must declare a variable before ajax code var dlg=$(this) ; and then on success i mus write dlg.dialog("close");
0

You need a web-service on the server side. (preferably REST)

http://restsharp.org/ is an easy to use library for that.

Take a look at this question for more info.

In the front end you make an ajax call to you're REST api (I see you use jquery so it won't be that hard ;))

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.