2

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

3 Answers 3

1

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();
    }
}
Sign up to request clarification or add additional context in comments.

Comments

1

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>

4 Comments

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
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
You may be able to do something similar with another CBE on the cancel button for the edit template.
sorry i don't know what are you talking ?
0

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;-)

2 Comments

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.