tags:

views:

1267

answers:

3

Hello Friends,

I am designing web application with asp.net c#. I am using gridview control.

In the gridview i have add,edit and delete button

I have one question is anybody know when user press cancel or update or delete button then massagebox will display and ask "Do you want to Update The Record " and option is YES and NO if user press yes then only record save other wise cancel.

**

*****> At the time of user press "Cancel
> Update" i want to check if any data is
> changed give message "Data is changed
> Do you want to cancel it" Yes or no if
> press yes then cancel other wise stay
> there.. how it's possible becz is ajax
> extender ask all time the time*****

**

How it's possible in web application ?

Thanks

+1  A: 

You can use the Ajax ASP.NET extender for button confirmation.

<TemplateColumn>
    <ItemTemplate>
      <asp:LinkButton id="lbDelete" runat="server" CommandName="Delete" Text="Delete"/>
      <cc1:ConfirmButtonExtender ID="cbeDelete" runat="server" 
          ConfirmText="Are you sure you want to delete this record?"
          TargetControlID="lbDelete" />
    </ItemTemplate>
    <ItemTemplate>
      <asp:LinkButton id="lbCancelUpdate" runat="server" CommandName="Cancel" Text="Cancel"/>
      <cc1:ConfirmButtonExtender ID="cbeCancel" runat="server" 
          ConfirmText="Are you sure you want to cancel any changes?"
          TargetControlID="lbCancelUpdate" />
    </ItemTemplate>
</TemplateColumn>
RSolberg
thanks.. when user press cancel button then if only data is changed in particular row then only it's show this message and in ajax extender it ask all time please help
Kartik
At the time of user press "Cancel Update" i want to check if any data is changed give message "Data is changed Do you want to cancel it" Yes or no if press yes then cancel other wise stay there.. how it's possible becz is extender it's ask all time
Kartik
You may be able to do something similar with another CBE on the cancel button for the edit template.
RSolberg
sorry i don't know what are you talking ?
Kartik
Check out the edits above...
RSolberg
A: 

In client side script for those buttons you want to do something like

if (confirm('Are you sure you want to delete this item'))
{
   //Do logic for delete item
}

Edit

Go and put this in a .html file on your pc and open it in a browser (if its ie7 you'll get security warning just allow it, this won't happen when launched from a url):

<html>
<body>
<script>

if (confirm('You want to delete me?')
{
 alert('deleted');
}
</script>
</body>
</html>

confirm is a function;-)

JoshBerke
i don't know where can i found "confirm" when i type confirm there is not any method call confirm
Kartik
confirm is a javascript function. JavaScript and intellisense aren't the best friends. You might get some but not a ton.
David Basarab
+1  A: 

I take a slightly different approach by extending the Button control. Just more general purpose.

<bo:LinkButton id="Button1" runat="server" ConfirmText="Delete?" />


public class LinkButton : System.Web.UI.WebControls.LinkButton
{
    [Bindable(true), Category("Behavior"), DefaultValue("")]
    public string AlertText
    {
        get { return (string)ViewState["AlertText"] ?? string.Empty; }
        set { ViewState["AlertText"] = value; }
    }

    [Bindable(true), Category("Behavior"), DefaultValue("")]
    public string ConfirmText
    {
        get { return (string)ViewState["ConfirmText"] ?? string.Empty; }
        set { ViewState["ConfirmText"] = value; }
    }

    protected override void CreateChildControls()
    {
        string script = string.Empty;

        if (AlertText.Length > 0)
        {
            script += string.Format("alert('{0}');", AlertText);
        }

        if (ConfirmText.Length > 0)
        {
            script += string.Format("return confirm('{0}');", ConfirmText);
        }

        if (script.Length > 0)
        {
            OnClientClick = script;
        }

        base.CreateChildControls();
    }
}
Andrew Robinson