如何在没有Ajax的ASP.NET 2.0中在执行C#代码的过程中打开showModalDialog

how to open showModalDialog in the middle of the C# code execution in ASP.NET 2.0 without Ajax

本文关键字:代码 执行 showModalDialog 过程中 Ajax ASP NET      更新时间:2024-01-08

我必须在C#代码执行的中间打开showModalDialog,并根据条件继续代码

代码如下

protected void Button_Click(object sender, EventArgs e)
{
 //some code execution
.
.
.       
 // need to open showModalDialog with yes & no button and wait for the click
string popupMessage = "<script language='javascript'>showmodal();</script>";
 ClientScript.RegisterClientScriptBlock(this.GetType(), "pop", popupMessage);
if (yes)
{
 // some code
}
else if (no)
{
 // some code
}
}  // End of Button click

请帮助我如何在没有Ajax 的情况下使用JavaScript

您应该调用ajax来实现此功能。

前任。

使用jquery的AJAX请求:

$.ajax(){
url: url,
success:function(response){
if(response.status === true)
//open modal
else
//some code
}}

使用javascript:的AJAX请求

function get(url) {
  // Return a new promise.
  return new Promise(function(resolve, reject) {
    // Do the usual XHR stuff
    var req = new XMLHttpRequest();
    req.open('GET', url);
    req.onload = function() {
      // This is called even on 404 etc
      // so check the status
      if (req.status == 200) {
        // Resolve the promise with the response text
        resolve(req.response);
      }
      else {
        // Otherwise reject with the status text
        // which will hopefully be a meaningful error
        reject(Error(req.statusText));
      }
    };
    // Handle network errors
    req.onerror = function() {
      reject(Error("Network Error"));
    };
    // Make the request
    req.send();
  });
}