Ok,
I have no problem displaying an alert when a button is clicked or at the end of a particular method. I can also call a confirm dialog when the user clicks a particular button, this is based on adding an attribute to the particular button in the page_load event. What I really really want to do is when the user clicks a button is go to the method called by that button and do some of the processing, then display a confirm dialog (i.e. "you have selected 10 people, do you want to give them a raise?", "OK, Cancel") and based on the users action I then either complete that action or abort it.
Now, I have figured a way of calling that confirm dialog in the middle of a method by doing the following:
Ok, when the method in step 3. is called, it displays the confirm dialog and waits for a response. If i click ok, then the method proceeds. I can click the cancel button till the cows come home, but my action is ignored and the rest of the method is executed.
Any suggestions on how to get around this annoying little problem.
Mike55.
I have no problem displaying an alert when a button is clicked or at the end of a particular method. I can also call a confirm dialog when the user clicks a particular button, this is based on adding an attribute to the particular button in the page_load event. What I really really want to do is when the user clicks a button is go to the method called by that button and do some of the processing, then display a confirm dialog (i.e. "you have selected 10 people, do you want to give them a raise?", "OK, Cancel") and based on the users action I then either complete that action or abort it.
Now, I have figured a way of calling that confirm dialog in the middle of a method by doing the following:
Code:
1. Add the following to the html code between the body and form tag:
<script>
<asp:Literal id="ltlAlert" runat="server" EnableViewState="False">
</asp:Literal>
</script>
2. Add the ltlAlert to the "Web Form Designer Generated Code" as follows:
Protected WithEvents ltlAlert As System.Web.UI.WebControls.Literal
3. I call the method with the required message:
Private Sub DisplayMessage(ByVal message As String)
message = message.Replace("'", "\'")
message = message.Replace(Convert.ToChar(10), "\n")
message = message.Replace(Convert.ToChar(13), "")
' A confirmation dialog.
ltlAlert.Text = "confirm('" & message & "')"
End Sub
Ok, when the method in step 3. is called, it displays the confirm dialog and waits for a response. If i click ok, then the method proceeds. I can click the cancel button till the cows come home, but my action is ignored and the rest of the method is executed.
Any suggestions on how to get around this annoying little problem.
Mike55.