views:

1533

answers:

5

Maybe I'm searching with the wrong keywords, but I can't find a solution to this.

I've got an ASPX page on which, within an <asp:Repeater> I want to insert a button (per item) that will:

  1. ask (JS "confirm") the user if they really want to proceed, then
  2. call a method on the page class passing in the ID (Guid) from that item.

I can do 1 or 2, but can't figure out how to call back into the page method from JavaScript.

I've tried turning on the EnablePageMethods in the ScriptManager, but that didn't seem to do what I expected -- calling PageMethods.Blah(...) did not seem to have any effect.

Are there any ready examples? In fact, the confirmation string is the same for every entry.

AtDhVaAnNkCsE

+2  A: 

You can perform the confirmation with the OnClientClick property of your button:

<asp:Button runat="server" ID="DeleteButton" CommandName="Delete"
 Text="Delete" OnClientClick="return confirm('Are you sure ?');" />
CMS
+1  A: 

here's what you need to do:

  1. make sure your button has runat="server"
  2. in that button, add onClientClick="javascript:return confirm('Are you sure?');"
  3. call your SERVER SIDE code from onClick even of the button

    <asp:Button id="Button1" Text="Do Stuff" OnClick="YOUR SERVER SIDE METHOD"    
      onClientClick="javascript: return confirm('Are you sure?');" runat="server"/>
    
roman m
A: 
<asp:Repeater ID="YourRepeater" runat="server">
    <ItemTemplate>
     <asp:Button ID="btnDelete" runat="server" OnClientClick="javascript:return confirm('Are you sure ?');" OnClick="btnDelete_OnClick" />
    </ItemTemplate>
</asp:Repeater>
J.13.L
A: 

Here's what you need to do:

  • enable script manager (which you did)

  • create a web service, which will handle a callback into your code:

    [WebService] [ScriptService] public class MyWebService : System.Web.Services.WebService { [WebMethod] public int SomeCallbackFunction() { .... } }

  • put a link to a web service proxy into script manager (generated by [ScriptService]):

        <asp:ScriptManager runat="server" ID="scriptManagerId">
            <Services>
                <asp:ServiceReference  Path="WebService.asmx" />
            </Services>
        </asp:ScriptManager>
    
  • In your javascript, you will be able to use the callback:

    function Blablabla() { MyWebService.SomeCallbackFunction() }

This is only a general idea, of course, this code probably needs some polishing. You can lookip for more examples here: http://msdn.microsoft.com/en-us/library/bb398995.aspx

galets
i think this is an overkill if all he wants is "confirmation dialog"
roman m
well.. he said he needed a callback to a server code
galets
A: 
NVRAM