Asked by:
Confirm box in between 2 update query in vb.net

Question
-
User-1578974752 posted
In between VB.NET code can I place confirm box. I have save command before and after the confirm box. so if the user clicks cancel,i don't want to execute the save command and if they click ok the save command must be executed.
Button1.Attributes.Add("onclick", "return window.confirm('Are you sure?');")
Thanks
Wednesday, October 30, 2019 9:36 AM
All replies
-
User-1780421697 posted
<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server"> <script> function update() { var txtValue = $("#EDITEDVAL").val(); if (confirm("Do you want to proceed? Edited Records for this Number: " + txtValue)) { return true; } else { return false; } } </script> <asp:Textbox ID="txt1" runat="server"></asp:Textbox> <asp:Textbox ID="txt2" runat="server"></asp:Textbox> <%-- I have set 2 as dummy value --%> <input type="text" id="EDITEDVAL" value="2" style="display:none" /> <asp:Button OnClientClick="return update()" OnClick="Save_Click" Text="Save" runat="server" /> </asp:Content> public partial class _Default : Page { protected void Page_Load(object sender, EventArgs e) { } protected void Save_Click(object sender, EventArgs e) { } }
Wednesday, October 30, 2019 10:09 AM -
User-1578974752 posted
confirm is showing but with out the txtvalue.
I will get the txtvalue only if the first update query execute in the Save_Click .
I want to execute the first portion of save_click then only the messagebox must show,then if click ok, the the second half in Save_Click must execute. Thanks
Thursday, October 31, 2019 3:19 AM -
User288213138 posted
Hi shsu,
I will get the txtvalue only if the first update query execute in the Save_Click . I want to execute the first portion of save_click then only the messagebox must show,then if click ok, the the second half in Save_Click must execute.
According to your description, i made demo for you.
<script> function showconfirm() { var r = confirm("Press a button!"); if (r == true) { alert("<%= after() %>"); //This is second half } else { alert("You pressed Cancel!"); } } </script> <asp:Button ID="Button1" runat="server" Text="Save" OnClick="Button1_Click" /> Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Response.Write("This is the first update query") ScriptManager.RegisterStartupScript(Me, Me.[GetType](), "script", "showconfirm();", True) End Sub Public Function after() As String Return "This is save command after" End Function End Class
The result:
Best regards,
Sam
Thursday, October 31, 2019 7:42 AM -
User-1780421697 posted
What i understand is
protected void Save_Click(object sender, EventArgs e) { // First Portion that do some task (executing query etc)
// Display Confirm Dialog //Execute Second Portion of Code }Now split it like
[WebMethod] public static int WebMethod() { //Return business logic, number of record updated or what ever
FirstPortion(); return 2; } protected void Save_Click(object sender, EventArgs e) { //may be actual transaction SecondPortion(); }i think you need to have a web method/web service/api method that should be called by Ajax and then in the success function you will get some result from web method that you need and then you can show confirm dialog and if it works then return true and in the Save method you only have second portion of code.
WebMethod that return some result or whatever is business logicClientside call
<script> function update() { var txtValue = $("#EDITEDVAL").val(); $.get('url', {}, function (result) { if (result>1) //let suppose updated fields or more then 1 ,just for example of business { if (confirm("Do you want to proceed? Edited Records for this Number: " + result)) { return true; } else { return false; } } }); return false; } </script>
Thursday, October 31, 2019 7:55 AM