ability to call a java script on click of a button.

Last post 03-20-2007 4:33 AM by rumbafum. 4 replies.

Sort Posts:

  • ability to call a java script on click of a button.

    03-20-2007, 1:33 AM
    • Loading...
    • Nitinkcv
    • Joined on 03-13-2007, 11:07 AM
    • Posts 264

    Hi,

     

    Currently im saving my records in to a database on the click of  a button.. what i want is, on click of that button it should call a java script prompt asking for confirmation. it needs to be done in C#. could anyone plaese help me out..

     
    Thanks

    Nitin.
     

    Thanks
    Filed under: ,
  • Re: ability to call a java script on click of a button.

    03-20-2007, 2:17 AM
    Answer
    • Loading...
    • XIII
    • Joined on 06-30-2002, 11:59 PM
    • Essen, Belgium
    • Posts 9,866
    • Moderator
      TrustedFriends-MVPs

    Hi,

    please take a look at the answers provided in this thread: http://forums.asp.net/thread/1626079.aspx.

    Grz,  Kris.

    Read my blog | Members are volunteers so please keep out the (it's urgent | asap | reply me directly) stuff. Nobody's interested in that.
  • Re: ability to call a java script on click of a button.

    03-20-2007, 2:35 AM
    Answer

    Let say your button name is btnSave.  you have to do add:

    btnSave.Attributes.Add("onClick","Javascript:showPrompt()");

    In Javascript function, you can do the followiing :

    function showPrompt()

    {

      var retVal = confirm("Are you sure to Save Record?");

    if (retVal == false)

    {

    event.returnValue = false;

    }

    }

     

    It will solve your problem for sure. If your problem has been resolved, please mark this post as resolved.

  • Re: ability to call a java script on click of a button.

    03-20-2007, 3:29 AM
    • Loading...
    • Nitinkcv
    • Joined on 03-13-2007, 11:07 AM
    • Posts 264

    Hi,

    Sorry i forgot to mention that my button is actually inside a repeater and it validates info from textboxes and ddl inside the repeater.. The prob is that i have "SELECT VALUE" chosen as the default value in my ddl. so while saving i want to check if the value in the DDL is not SELECT VALUE, then only it should save those..

    so right now my code is

     

    private void Item_Created(Object Sender, RepeaterItemEventArgs e)
            {
                if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
                {
                    Button _deleteButton = (Button)e.Item.FindControl("btnDelete");
                    _deleteButton.Attributes.Add("onclick", "return deleteUser();");

                    Button _moveUserButton = (Button)e.Item.FindControl("btnMoveUser");
                    DropDownList _dll = (DropDownList)e.Item.FindControl("lstStudyType1");
                    string _group = _dll.SelectedValue;
                    if (_group !="SELECT VALUE")
                    {
                     
                        _moveUserButton.Attributes.Add("onclick", "return moveUser();");
                    }
                    else
                    {
                        _moveUserButton.Attributes.Add("onclick", "return showAlert();");
                    }

                }

            }

     

    function showalert ()

    {

    alert('please select a value');

    return false

    }

    function moveUser()
    {

      var answer=confirm("Are you sure you want to move this candidate?");
      if(answer)
      return true;
      else
      return false;
     
    }

     

    But the code inside item_created does not work.. it even if ddl value is SELECT VALUE.. the moveUser() function is always called..

     

    Thanks,

    Nitin. 

    Thanks
  • Re: ability to call a java script on click of a button.

    03-20-2007, 4:33 AM
    • Loading...
    • rumbafum
    • Joined on 10-13-2005, 9:41 AM
    • Lisboa
    • Posts 225
    Check for your Selected Value if it's really "SELECT VALUE" and use String.Equals to Compare the strings also
Page 1 of 1 (5 items)
Microsoft Communities
Page view counter