简体   繁体   中英

How to call server-side function from client-side in ASP.NET?

I have a web page having asp.net button control and textbox. I want a confirm message box, when someone changes the content of textbox and click on button. If user click on yes then event of button should fire other wise nothing should happen. All I want is to implement AJAX call back, but it is not working with ASP.NET button control.

只需将以下代码添加到您的aspx代码中

<asp:Button ID="btn1" OnClientClick="return confirm('sure?');" runat="server" Text="Button" />

You can use the ConfirmButtonExtender of the AjaxControlToolkit for this purpose,

http://www.asp.net/ajax/ajaxcontroltoolkit/Samples/ConfirmButton/ConfirmButton.aspx

您也可以在ASP.Net中使用Client Callback ,这在ASP.Net中确实是一个不错的功能

Please refer to http://msdn.microsoft.com/en-us/library/ms178208.aspx . Hope it helps :)

Combining the use of OnClientClick with javascript's confirm as suggested by Pilgerstorfer Franz, with an update panel for the ajax request you mentioned...

<asp:UpdatePanel runat="server">
   <ContentTemplate>
       <asp:TextBox ID="txtInput" runat="server"/>
   </ContentTemplate>
   <Triggers>
     <asp:AsyncPostBackTrigger ControlID="btnSubmit" />
   </Triggers>
</asp:UpdatePanel>

<asp:Button ID="btnSubmit" OnClientClick="return confirm('Are you sure you want to submit?');" runat="server" Text="Submit" />

Should give you want you need.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM