Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET VB.NET
Hi,
 
how can i show a message box in an asp.net page that would show once a button is clicked.
the message box should have "Yes" and "Cancel" as 2 buttons and the rest of the VB.net code should only be executed if "Yes" is clicked.
 
seeking help on this
 
thanks
Joe
Posted 10-Oct-11 2:24am
joe_j4K
Edited 10-Oct-11 2:31am
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

you can take a help of Javascript.
use Confirm() function. here is example
 
function askConfirm()
{
  if(confirm("are you sure"))
    alert("you clicked Yes")
  else
    {
      alert("you clicked No") 
      return false;
    }
}
 
add this function on your submit button click.
 
"return false" will cancel your execution.
 
call following function in ASPX page like this
 
<asp:button id="btnSubmit" runat="Server" text="Submit" onclientclick="return askConfirm()" >
  Permalink  
v2
Comments
Member 4332304 at 10-Oct-11 7:46am
   
but if the user clicks YES then i need to execute functions that are coded with VB.net in the code behind page.
so how do i get if yes, then execute the codebehind code?
 
thanks
koolprasad2003 at 10-Oct-11 7:48am
   
Dear friend, code behind get automatically called after Javascript execute.
if you clicked YES your code behind will called automatically.
paste the code and see the output.
Member 4332304 at 10-Oct-11 7:54am
   
i got the onclientclick whihc i have added,
but im pretty confused with where to add function askConfirm() and the rest of the code.
if i put it into the Button1_Click codebehind, it gives me an error
Member 4332304 at 10-Oct-11 8:00am
   
oooh k.. i think i got it..
the java script without the <script type="text/javascript"> kinda got me confused if it was c# code or javascript.. thanks for that koolprasad.
Member 9480676 at 6-Nov-12 6:02am
   
I have doubt.
If i press the Submit button in one Form,i want to display one PopUpBox with
Yes or No Buttons.In that Box If i Press YesButton again
one more popUpBox i want to display with One Label along with TextBox and Save Button.
First PopUpBox i did.But second popUp Box with label,TextBox and Save button how to do?
Plz provide solution to me .
koolprasad2003 at 9-Nov-12 23:57pm
   
With the Help of Javascript you can not easily put label, textbox and button. Better to Design a from as per your requirement and call it as POPUP with the help of Javascript.
Check my latest reply.
Best luck.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

you can take a help of Javascript.
use Confirm() function. here is example
 
function askConfirm()
{
  if(confirm("are you sure"))
    alert("you clicked Yes")
  else
    {
      alert("you clicked No") 
      return false;
    }
}
 
add this function on your submit button click.
 
"return false" will cancel your execution.
  Permalink  
v2
Comments
Member 4332304 at 10-Oct-11 7:37am
   
thanks for that reply. but do i add the above after this?
Protected Sub Button1_Click(sender As Object, e As System.EventArgs) Handles Button1.Click
koolprasad2003 at 10-Oct-11 7:40am
   
no, not at all.
you have to add this in ASPX page. see my changed reply
Member 9424392 at 9-Jun-13 6:15am
   
I want to pop up the message box after some activity has been done on click event and then want to ask the confirmation message box
please help me :)
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

if(result>0)
{
string myscript = "alert ('message');";
                    Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "MyScript", myscript, true);
                    return false;
}
 

 

hope this will work....
  Permalink  
v2
Comments
Member 4332304 at 10-Oct-11 7:44am
   
could you please let me know this in vb.net code
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

Insted of msgbox use confirm from javascript.
it has two buttons "ok" and "cancel".
 
msgbox will execute on the server while confirm executes on client.
you can code for confirm like this:
if(confirm("Are you sure to reload data?")){
    grid.reload();
}else{
    //to do nothing
}
  Permalink  
Comments
Member 4332304 at 10-Oct-11 7:48am
   
hi,
confirm in vb.net is giving an error
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

hope this helps
 
Private Sub Test_Click()
Dim testmsg As Integer
testmsg = MsgBox("Click to test", 1, "Test message")
If testmsg = 1 Then
Display.Caption = "Testing Successful"
Else
Display.Caption = "Testing fail"
End If
 
End Sub
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 6

add this property to your button
OnClientClick="return confirm('Are you sure you want to Proceed ?');"
 
like this
<asp:button id="btnDelete" runat="server" onclick="btnDelete_Click" onclientclick="return confirm('Are you sure you want to Proceed ?');"  />
  Permalink  
v2
Comments
Member 9424392 at 9-Jun-13 6:13am
   
In button can I add multiple functions in OnclientClick()
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 7

Try this.
<asp:button id="btn" runat="server" xmlns:asp="#unknown">OnClientClick="javascript:return confirm('Are you sure you want to delete this user?')" /></asp:button>
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 10

you can use on clientClick Property of Button
for example
 
<asp:button id="btnSubmit" runat="Server" text="Submit" onclientclick="return askConfirm()" xmlns:asp="#unknown">
 
and for back end you are use following code for it
 
if(result>0)
{
string myscript = "alert ('message');";
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "MyScript", myscript, true);
return false;
}
  Permalink  
Comments
Member 9424392 at 9-Jun-13 6:12am
   
I m getting an error "Name result unknown error" in code
what should I do
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 11

Try This:

1) Right Click on Solution Explorer & Add reference the "System.windows.Forms";

2) Now create a button in Default.aspx.

3) Double click on that button, Default.aspx.cs will open.

4) In that first of all add a namespace at the top "System.windows.Forms".

5) Now in button1 coding block write code,

Collapse | Copy Code
protected void Button1_Click(object sender, EventArgs e)
{
MessageBox.Show("yes.", "AIOOB", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);

}
6) Now it is done.

Gaurav Bhardwaj
B.Tech (Computer Science Engineering).
Developed Many Projects in ASP.NET.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 12

check following code snippet which helps you lot
 
<head>
  <script language="Javascript">
   function showPOPUP()
   {
      if(confirm("Do you want to continue")) //show 1st popup
      {
        window.open('Default2.aspx','_blank'); //show your aspx page as POPUP
      } 
      else
      {
         alert("You pressed cancel");
      }
   }
  </script>
</head>
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 14

You can create Messagebox in asp.net page,
 
I have found useful link below.
 
http://tinyurl.com/ovggplb[^]
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web04 | 2.8.1411022.1 | Last Updated 9 Jul 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100