Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get Confirm result using Code-behind

Status
Not open for further replies.

vilrbn

Programmer
Oct 29, 2002
105
FR
Hello,

I'm using this code to pop up a confirm msg:

lblMsg.Text = &quot;<SCRIPT language = 'javascript'>doSubmit = confirm('Warning: This file already exists !');</script>&quot;

I want to get back the result (ok or cancel) on code-behind side. I tried to replace doSubmit with

window.document.Form1.MyLbl.value

where MyLbl is an ASP.Net label or an HtmlInputText but in both cases, the result is undefined.
I absolutely need to get the value on VB side as I don't know how to code what follows the pop up msg in Javascript.

Can you help me ?
 
Do you need to have code run on both ok and cancel or just on ok.

If you only need code to run on ok then Add the confirm bit to the onclick of a button and just do a return(confirm(''))

This way if the user presses cancel nothing will happen if they press ok then a post back will occur. That'l do donkey, that'l do
[bravo] Mark
If you are unsure of forum etiquette check here faq796-2540
 
Hello Mark,

I only have to run code on Ok.
I don't understand how to use your button.

I already have one button:
<asp:button id=&quot;cmdUpload&quot; onclick=&quot;Add_Image&quot; runat=&quot;server&quot; Text=&quot;Add...&quot;></asp:button>

In my Add_Image function, in certain cases, I call a Javascript function to pop up a confirm. If the user click on OK, I continue my code in VB.

code-behind:

lblMsg.Text = &quot;<SCRIPT language = 'javascript'>Test();</script>&quot;

Javascript file:

function Test(){
var doSubmit
doSubmit = confirm('blabla');
document.Form1.Label1.value = doSubmit;
return doSubmit;
}

document.Form1.Label1.value is always undefined. I tried to use WebControls and HtmlControls unsuccessfuly.
Return doSubmit returns doSubmit value, but how can I catch and use it in my code-behind ?

 
This is what I do and it works just fine. Put this code into your page_load routine.


cmdUpload.Attributes.Add(&quot;onclick&quot;, &quot;javascript:return confirm('blabla')&quot;)


I use it myself. That'l do donkey, that'l do
[bravo] Mark
If you are unsure of forum etiquette check here faq796-2540
 
Many thanks Mark !
It's working fine.
 
Hello Mark,
I have another question as javascript is not very clear for me...
If I put this code:

cmdUpload.Attributes.Add(&quot;onclick&quot;, &quot;javascript:return confirm('blabla')&quot;)

on the page load, it will pop up each time the cmdUpload button is pressed.

If I want to send a pop up in certain cases only, how can I do this ?

I tried to put the code in the function where the messagebox can be send, but apparently it's &quot;too late&quot; and not taken in account on client side.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top