Confirmation message box in webapplication

后端 未结 8 1663
刺人心
刺人心 2020-12-19 19:16

Am using the below message box in asp.net web application. Now i want to convert this message box as a confirmation message box and do something when it is true else means r

8条回答
  •  太阳男子
    2020-12-19 19:28

    To do this completely within C#, you can try this:

        protected override void OnInit(EventArgs e)
        {  
            AddConfirmationButton();   
            base.OnInit(e);
        }
    
        private void AddConfirmationButton()
        {   
            Button confirmButton = new Button();
            confirmButton.Text = "Action Foo";
            string confirmationMessage = "Are you sure you wish to do action Foo?";
            confirmButton.OnClientClick = "return confirm('" + confirmationMessage + "');";
            confirmButton.Command += confirmButton_Command;
    
            Controls.Add(confirmButton);
    
        }
    
        void confirmationMessage_Command(object sender, CommandEventArgs e)
        {
            DoActionFoo();   //work your magic here.
        }
    

    This presents and "OK/Cancel" dialog box to the user from the webpage. If the user clicks 'ok', the function from the command Event fires. If the user clicks 'cancel', nothing happens.

提交回复
热议问题