Want to call jscript "confirm" box from VB.NET, but NOT from a button

itlotl

Member
Joined
Nov 21, 2005
Messages
8
Programming Experience
3-5
In looking around on the internet to find out how to use a "messagebox"-like window on a webform, I have come across a few examples of how to do so from the "onclick" event of a button. In my situation I am using a third party treeview control that has a context menu on each node. If a user clicks on one of the context menu options, I would like for a "confirm" box to pop up and make sure that's what they wanted to do. I would be very grateful if someone could explain to me how to do one of the following:1) Cause one of these confirm boxes to pop up by calling it directly from the context menu eventhandler in my serverside VB.NET code2) Cause the "click" event on a button to fire from the same context menu eventhandler in my serverside VB.NET code (the idea being that I could hide one of these buttons I've seen that calls a "confirm" box, "click" it from my code, and all the user would see is the "confirm" box popping up when they click on the context menu)I've tried everything I can find on either subject and I'm just plain stuck.Thanks in advance for any advice,JT
 
First thing to remember is that the client code runs on the client and the server code runs on the server... you can't have server code opening dialog boxes on the client, it's impossible.

So to accomplish what you're looking for, it sounds like your tree node context menu clicks are causing a postback to occur, and basically you want to insert inbetween the click and the postback a confirmation dialog.

To do this you have to add a onclick event to the context menu item to display the confirmation. for example...

in your server-side vb.net code, to set an onclick event you would typically do something like:
VB.NET:
treenode.contextmenu.items(0).attributes.add("onclick","javascript:return showConfirm();")
Given that your treenode is a 3rd party you'll have to figure out how to have each context menu item call a javascript function.

note that in my example the onclick function is 'return showConfirm()'... the key here is the 'return' key word. if the showConfirm() javascript returns true then your postback will continue... otherwise the postback will not occur.

so here's what your showConfirm() javascript function could look like:
VB.NET:
<script language="javascript">
function showConfirm(){
var bConfirm = confirm('Are you sure?');
return bConfirm;
}
</script>

if you want to customize the 'Are you sure' message per context menu item, change your showConfirm() to accept an argument, like showConfirm(sMessage) then use that argument in the Confirm call...
 
Back
Top