When the user clicks a certain LinkButton, I need to open a confirmation dialog with OK/Cancel. If the user hits OK, then I need to run a function from ASP.NET (something to update the database).
Something like the following...
Javascript
function openConfirm() {
     return window.confirm("Are you sure you want to do this?");
}
ASP
<asp:LinkButton runat="server" CommandName="viewPart" onClick="if(openConfirm() === true) <% SomeASPFunctionCall() %>;">
    Delete
</asp:LinkBut开发者_JS百科ton>
The catch is that my application is running ASP.NET 1.1, so any references to adding an OnClientClick to the control is irrelevant (because OnClientClick has been added for ASP 2.0). I have tried postbacks via __doPostBack and the __eventObject and __eventArguments, but those simply do not work or I can't figure it out.
How should I manage this combination of client-side/server-side interaction?
Thank you
your linkButton has no ID, are you sure?
put an ID to it, let's imagine it's called myLinkButton (don't use this id please :D )
in the Page_PreRender put this code:
myLinkButton.Attributes.Add("onClick", "return window.confirm('Are you sure you want to do this?'");
it's pseudo code but should build and work also in .NET 1.1 I think, I am not using it since ages...
Edit: inside your grid, in the ItemDataBound or RowDataBound event depending on Framework and Grid version... put something like this:
private void myDataGrid_ItemDataBound(object sender, DataGridItemEventArgs e)
{
    if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
    {
        var myControl =  (LinkButton)e.Item.FindControl("myLinkButton");
        if(myControl != null)
        {
            myControl.Attributes.Add("onClick", "return window.confirm('Are you sure you want to do this?'");
        }
    }
}
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论