nar86 Ответов: 1

Как получить return true или false из javascript в код позади


функция confirm_meth() {
var confirmed = confirm('там есть еще несколько предметов с таким же номером скольжения. Вы хотите продолжить');
если (подтверждено == true) {
вернуть true;
}
еще {
возвращать false;
}
}

Элемента управления scriptmanager.RegisterStartupScript(страницы, метод gettype(), "confirm_meth", "confirm_meth()", правда);

Отправить код кнопки следующим образом

string url = строка.Пустой;
bool isAgri = true;
int count = 0; //добавлено
foreach (строка GridViewRow в grdRpt.Rows)
{
Флажок ЧК = (флажок)grdRpt.Строк[подряд.Параметр rowindex].FindControl("chkselecdata");
если (ЧК.Проверено == верно)
{
считать++;
int key = конвертировать.ToInt32(grdRpt.DataKeys[строка.Параметр rowindex].Значение);
if (row.Cells[4].Text == "Agri Input")
{
isAgri = истина;
url = ConfigurationManager.AppSettings["SAPAgriInputPostingUrl"].Метод toString();
}
перерыв;
}
}

 String strConnString = ConfigurationManager.ConnectionStrings["IvcSpiderDBConnectionStrings"].ConnectionString;
                SqlConnection con = new SqlConnection(strConnString);
                con.Open();
                if (count > 0)
                {
                    if (isAgri)
                    {
                        string slip_No = string.Empty;
                        List<string> slipnoList = new List<string>();
                        List<dist_request> dist_requests = new List<dist_request>();
                        foreach (GridViewRow row in grdRpt.Rows)
                        {
                            CheckBox cb = (CheckBox)row.FindControl("chkselecdata");
                            if (cb.Checked == true)
                            {
                                int key = Convert.ToInt32(grdRpt.DataKeys[row.RowIndex].Value);

                                slip_No = row.Cells[2].Text;
                                Dist_Request dist_request = new Dist_Request();
                                LT_ITEMS lT_ITEM = new LT_ITEMS();
   lT_ITEM.MATNR = row.Cells[15].Text == " " ? string.Empty : row.Cells[15].Text;
   
  dist_request = dist_requests.Where(r => r.SLIP_NO == slip_No).FirstOrDefault();
             if (dist_request != null && dist_request.SLIP_NO != null)
               {
dist_requests.Find(f => f.SLIP_NO == slip_No).PostingNav.Add(lT_ITEM);
dist_requests.Find(f => f.SLIP_NO == slip_No).FLAG += "," + key.ToString();
               }
      else
             {
                  dist_request = new Dist_Request();
                  dist_request.SLIP_NO = slip_No;
                  dist_request.BUDAT = DateTime.Now.ToString("yyyyMMdd");
                  dist_request.MBLNR = string.Empty; 
                            dist_request.FLAG = key.ToString();
                           List<lt_items> lT_ITEMs = new List<lt_items>();
                           List<returnnav> listreturnNav = new List<returnnav>();
                           lT_ITEMs.Add(lT_ITEM);
                          dist_request.PostingNav = lT_ITEMs;
                          dist_request.ReturnNav = listreturnNav;
                          dist_requests.Add(dist_request);
            }

 }
                            else
                            {
                                slip_No = row.Cells[2].Text;
                                slipnoList.Add(slip_No);
                            }
                        }
                        HttpHelper httpHelper = new HttpHelper();
                       if (dist_requests.Count > 1)
                        {
                            ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('More than one slip no selected no');", true);
                            return;
                        }

                         else
                        {
                            
   if (slipnoList.Contains(dist_requests.FirstOrDefault().SLIP_NO))
                            {
                                        System.Web.UI.ScriptManager.RegisterClientScriptBlock(Page, typeof(System.Web.UI.Page), "Script", "confirm_meth();", true);

                             }

 In the runmode when i click the submit  i get alert message as "There are some more items with same slip number is there. Do you want to proceed?" 
 
  Ok Cancel.

i click ok 
in the below line i cannot get the System.Web.UI.ScriptManager.RegisterClientScriptBlock(Page, typeof(System.Web.UI.Page), "Script", "confirm_meth();", true);

retrun value

what is the mistake in my above code?

What I have tried:

function confirm_meth() {
            var confirmed = confirm('There are some more items with same slip number is there. Do you want to proceed');
            if (confirmed == true) {
                return true;
            }
            else {
                return false;
            }
        }

ScriptManager.RegisterStartupScript(Page, GetType(), "confirm_meth", "confirm_meth()", true);

 Submit button code as follows

string url = string.Empty;
bool isAgri = true;
int count = 0; //added
foreach (GridViewRow row in grdRpt.Rows)
{
CheckBox chk = (CheckBox)grdRpt.Rows[row.RowIndex].FindControl("chkselecdata");
if (chk.Checked == true)
{
count++;
int key = Convert.ToInt32(grdRpt.DataKeys[row.RowIndex].Value);
if (row.Cells[4].Text == "Agri Input")
{
isAgri = true;
url = ConfigurationManager.AppSettings["SAPAgriInputPostingUrl"].ToString();
}
break;
}
}

<pre> String strConnString = ConfigurationManager.ConnectionStrings["IvcSpiderDBConnectionStrings"].ConnectionString;
                SqlConnection con = new SqlConnection(strConnString);
                con.Open();
                if (count > 0)
                {
                    if (isAgri)
                    {
                        string slip_No = string.Empty;
                        List<string> slipnoList = new List<string>();
                        List<dist_request> dist_requests = new List<dist_request>();
                        foreach (GridViewRow row in grdRpt.Rows)
                        {
                            CheckBox cb = (CheckBox)row.FindControl("chkselecdata");
                            if (cb.Checked == true)
                            {
                                int key = Convert.ToInt32(grdRpt.DataKeys[row.RowIndex].Value);

                                slip_No = row.Cells[2].Text;
                                Dist_Request dist_request = new Dist_Request();
                                LT_ITEMS lT_ITEM = new LT_ITEMS();
   lT_ITEM.MATNR = row.Cells[15].Text == " " ? string.Empty : row.Cells[15].Text;
   
  dist_request = dist_requests.Where(r => r.SLIP_NO == slip_No).FirstOrDefault();
             if (dist_request != null && dist_request.SLIP_NO != null)
               {
dist_requests.Find(f => f.SLIP_NO == slip_No).PostingNav.Add(lT_ITEM);
dist_requests.Find(f => f.SLIP_NO == slip_No).FLAG += "," + key.ToString();
               }
      else
             {
                  dist_request = new Dist_Request();
                  dist_request.SLIP_NO = slip_No;
                  dist_request.BUDAT = DateTime.Now.ToString("yyyyMMdd");
                  dist_request.MBLNR = string.Empty; 
                            dist_request.FLAG = key.ToString();
                           List<lt_items> lT_ITEMs = new List<lt_items>();
                           List<returnnav> listreturnNav = new List<returnnav>();
                           lT_ITEMs.Add(lT_ITEM);
                          dist_request.PostingNav = lT_ITEMs;
                          dist_request.ReturnNav = listreturnNav;
                          dist_requests.Add(dist_request);
            }

 }
                            else
                            {
                                slip_No = row.Cells[2].Text;
                                slipnoList.Add(slip_No);
                            }
                        }
                        HttpHelper httpHelper = new HttpHelper();
                       if (dist_requests.Count > 1)
                        {
                            ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('More than one slip no selected no');", true);
                            return;
                        }

                         else
                        {
                            
   if (slipnoList.Contains(dist_requests.FirstOrDefault().SLIP_NO))
                            {
                                        System.Web.UI.ScriptManager.RegisterClientScriptBlock(Page, typeof(System.Web.UI.Page), "Script", "confirm_meth();", true);

                             }

 In the runmode when i click the submit  i get alert message as "There are some more items with same slip number is there. Do you want to proceed?" 
 
  Ok Cancel.

i click ok 
in the below line i cannot get the System.Web.UI.ScriptManager.RegisterClientScriptBlock(Page, typeof(System.Web.UI.Page), "Script", "confirm_meth();", true);

retrun value

what is the mistake in my above code?

1 Ответов

Рейтинг:
2

Richard MacCutchan

Это тот же самый вопрос, что и Предупреждающее сообщение пользователю ok или отмена с помощью C#[^]. Пожалуйста, ответьте в исходном сообщении, а не перепечатывая его.