c# 서버측 버튼을 클릭하여 confirm 기능 구현

6091 단어 confirm
제가 접촉한 두 가지 버튼이 confirm 기능을 실현한다고 말씀드릴게요.
일반 서버 button 컨트롤:
 
<asp:Button ID="Button1" runat="server" OnClientClick="if(!confirm('Submit form?')){return false;}" OnClick="Button1_Click" Text="Button" />

 
심볼에 OnClientClick 이벤트를 등록하면 Submit 전에 사용자에게 확인하고 확인한 후에submit을 하고 그렇지 않으면 submit을 하지 않습니다.
 
GridView의 command 버튼:
        protected void gvProject_RowCommand(object sender, GridViewCommandEventArgs e)

        {

            try

            {

                string[] parameters = e.CommandArgument.ToString().Split('|');

                int rowIndex = Convert.ToInt32(parameters[0]);

                bool confirmResult = false;//         ,        false

                if (parameters.Length == 2)

                {

                    bool.TryParse(parameters[1], out confirmResult);

                }

                if (!confirmResult)//              

                {

                    //          

                    string commandArgument = e.CommandArgument.ToString() + "|true";

                    string commandProjectName = this.gvProject.Rows[rowIndex].Cells[0].Text;

                    string scriptString = @"

                                            <script>

                                                if(window.confirm('         {" + commandProjectName + @"} ?'))

                                                {

                                                    __doPostBack('gvProject','$" + commandArgument + @"')

                                                }

                                             </script>";

                    ClientScript.RegisterClientScriptBlock(this.GetType(), "billConfirmAlert", scriptString);

                }

                else//              

                {

                    //  DataKeys  projectID

                    int projectID = Convert.ToInt32(this.gvProject.DataKeys[rowIndex].Values["ProjectID"]);

                    projectController.ActivateProject(projectID, "");

                    //         

                    ShowNotActivatedProject();

                }

            }

            catch (Exception ex)

            {

                this.lblResult.Text = string.Format("      :{0}", ex.Message);

            }

        }

주석이 상세하니 여러분 직접 보세요.
 

좋은 웹페이지 즐겨찾기