Message box in asp.net

  • Thread starter Thread starter ratnakarp
  • Start date Start date
R

ratnakarp

hi,

i want to pop up a message box when a button is clicked. the situation
is something like this as follows.


protected void button1_click(.. , ..)
{
.......
........
.......

response.write(<script language="javascript"> or
language="vbscript">confirm or msgbox or etc..</script>)
if(clicked yes)
{
do the following

}
else
get out of the method

}


is there any way if user clicks yes on the confirm box or message box,
the rest of the code in button1 click method should be executed
otherwise get out of the method. Any help or reference is appreciated.

Thanks,
Ratnakar Pedagani
 
btn.Attributes.Add("onClick", "return confirm('Do you really want to delete
the record?');");

HTH

Elton Wang
 
Hello Elton,

Thanks for your reply, but here i'm facing the problem., i forgot to
add a condition. i changed the code. In the following code, if the
cond1 is true, then the confirm message should pop up. if clicked yes,
i should be able to do something else within button click method. for
example

protected void button1_click(.. , ..)
{
x=callmethod1();
y=callmethod2();
z=str1;

if(z>40)
{
//pop up confirm box, "do you want to continue"
response.write(<script language="javascript"> or
language="vbscript">confirm or msgbox or etc..</script>)
if(clicked yes)
{
save the details in the database;
}
else
{
get out of the method
}
}

can you please let me know how to proceed further. Kindly let me know
if you need to know anything else.

Thanks & Regards,
Ratnakar Pedagani.
 
You should know that client-server (Web) application is different from
desktop one. Especially, in server-side code you can’t directly interact with
user. What I can suggest is to put your logic on client-side (javascript
function(s)). Only when postback, on server-side to save detail to DB:

Server Code:
Page_Load(){
// ...
btn.Attributes.Add("onClick", "return CheckZ();");
}

btn_Click(...)
{
// save info;
}

Client code:

<script>
function CheckZ()
{
var z = getZ;
if(z <=40)
{
return false;
}
Return confirm(confirm message);
}
</script>


HTH
 
Do you guyz got any other ideaz, looks like these things are not
working for me? Thanks for your help

Regards,
Ratnakar Pedagani
 
Back
Top