如何从按钮后面的代码中调用javascript函数,点击并存储其输出,然后继续操作



我的javascript代码:

   function Confirm()
    {
     var confirm_value = document.createElement("INPUT");
     confirm_value.type = "hidden";
     confirm_value.name = "confirm_value";
     if (confirm("UserID already exists...Do you want to update            information?"))
      {
         confirm_value.value = "Yes";
      }
     else
      {
          confirm_value.value = "No";
       }
            document.forms[0].appendChild(confirm_value);
     }

我的asp.net代码点击按钮:

         protected void Btn_Create_Click(object sender, EventArgs e)
           {
               bool check;
               _objClsCreateUsers = new ClsCreateUsers();
                check = _objClsCreateUsers.CheckUserID(Txt_UserID.Text);
              if (check == true)
               {
                     ScriptManager.RegisterClientScriptBlock(this,                        this.GetType(),            "alertMessage", "Confirm();", true);
                    string confirmValue = Request.Form["confirm_value"];
             if (confirmValue == "Yes")
                {
                    _objClsCreateUsers.UpdateData(Txt_UserID.Text,    Txt_UserName.Text,               Txt_Password.Text, Lst_Department.Text,                                                   Convert.ToDateTime(Txt_ExpiredOn.Text),    Convert.ToBoolean(Lst_IsAdmin.Text));
                   ScriptManager.RegisterClientScriptBlock(this,                                                                this.GetType(),                                                                          "alertMessage", "alert('Record Updated Successfully')", true);
                ClearAll();
enter code here
            }
            else
            {
                Txt_UserID.Text = "";
            }
        }
        else
        {
            _objClsCreateUsers.InsertData(Txt_UserID.Text, Txt_UserName.Text, Txt_Password.Text, Lst_Department.Text, Convert.ToDateTime(Txt_CreatedOn.Text), Convert.ToDateTime(Txt_ExpiredOn.Text), Convert.ToBoolean(Lst_IsAdmin.Text));
            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('User Created Successfully')", true);
            ClearAll();
        }
    }

我在获取javascript函数输出的输出值时遇到了问题。

Javascript在按钮点击的完整代码运行后运行。我希望它在代码中间运行。

谢谢。

考虑到这是一种创建帐户的形式,我认为理想的方式应该如下

当UserID文本框中的值发生更改时,您应该进行ajax调用。或者为文本控件绑定服务器端事件(希望您使用的是服务器控件)。在这个AJAX调用中,如果用户id已经存在或不存在,您可以从服务器获得结果,并同时显示消息本身。

在提交时,您应该再次检查用户ID是否已经存在,并在没有确认的情况下直接更新信息。如果ID不存在,则插入

最新更新