locked
confirm box in a webpart RRS feed

  • Question

  • Hi,


        well i m pretty new to wss.. i have developed a simple webpart .. it consists of a label , drop down and a button ... wat it does is select a value from the drop down and and on click delete the named document library ...
      i have the following criteria  on click i want a javascript like confirm method . if yes delete the item or else do nothing ..


     My question is can we do it and if yes how.


    sample is below

     onclick()
    {
     
            if dropdown selected
    {

    confirm method
    if yes
       {
           delete the selected document libray
        }
    else
         skip the loop

      }
    }


    Any help or idea of any sought would be helpfully


               Thank  u
    Wednesday, February 11, 2009 7:02 PM

Answers

  • HI there

    You need to code the Javascript function to return true or false. Something like this:

    function ConfirmDelete()  
    {  
      if(yes)  
         return true;  
      else 
         return false;  

    Then, set the asp:button's OnClientClick property to "return ConfirmDelete();"

    <asp:Button ID="btnSave" runat="server" onClientClick="return ConfirmDelete();" onClick="btnSave_click" /> 

    If the javascript function returns true then the server click event will be fired, otherwise it will be ignored.

    Stu
    Starznet SharePoint Blog : http://www.starznet.co.uk/sharepoint/blog
    Please mark replies as answered if you find it has helped you
    Contact : http://www.starznet.co.uk/contactstarznet.htm
    • Proposed as answer by O Town Wednesday, February 11, 2009 8:01 PM
    • Marked as answer by Michael Washam - MSFT Thursday, February 12, 2009 2:13 PM
    Wednesday, February 11, 2009 7:18 PM
  •  

    For the dialog to pop up use something like...

     
    function confirmDelete()  
    {  
     
        var answer = confirm("Are you sure you want to delete this?")  
        if (answer)  
        {  
            return true;  
        }  
        else
        {  
            return false;  
        }  
     
     
    Wednesday, February 11, 2009 8:04 PM

All replies

  • HI there

    You need to code the Javascript function to return true or false. Something like this:

    function ConfirmDelete()  
    {  
      if(yes)  
         return true;  
      else 
         return false;  

    Then, set the asp:button's OnClientClick property to "return ConfirmDelete();"

    <asp:Button ID="btnSave" runat="server" onClientClick="return ConfirmDelete();" onClick="btnSave_click" /> 

    If the javascript function returns true then the server click event will be fired, otherwise it will be ignored.

    Stu
    Starznet SharePoint Blog : http://www.starznet.co.uk/sharepoint/blog
    Please mark replies as answered if you find it has helped you
    Contact : http://www.starznet.co.uk/contactstarznet.htm
    • Proposed as answer by O Town Wednesday, February 11, 2009 8:01 PM
    • Marked as answer by Michael Washam - MSFT Thursday, February 12, 2009 2:13 PM
    Wednesday, February 11, 2009 7:18 PM
  •  

    For the dialog to pop up use something like...

     
    function confirmDelete()  
    {  
     
        var answer = confirm("Are you sure you want to delete this?")  
        if (answer)  
        {  
            return true;  
        }  
        else
        {  
            return false;  
        }  
     
     
    Wednesday, February 11, 2009 8:04 PM
  • Why not 


    protected override void CreateChildControls()
            {
    this.btnSubmit = new Button();
                this.btnSubmit.ID = "_btnSubmit";
                this.btnSubmit.Text = "OK";
                this.btnSubmit.Width = Unit.Pixel(50);
                this.btnSubmit.Click += new EventHandler(btnSubmit_Click);
     this.btnSubmit.Attributes.Add("onclick", "if (! confirm('Delete?')){return false;}");

    //The return false; javascript method cancel the postback...

    this.Controls.Add(btnSubmit);

    }

    Hope this help....

    André Lage Microsoft SharePoint and CRM Consultant http://aaclage.blogspot.com
    Thursday, February 12, 2009 10:04 AM
  •  It worked.. My fundamentals are quite weak , thank u guys
    Saturday, February 14, 2009 7:55 AM