0

I need to display a YesNo messagebox, in case of a server side code execution failure. As far as I can tell, you can't show a messagebox from the server side. Is a walk around of sorts, where I fire a hidden button's OnClientClick Event programmatically in order to display a messagebox is possible? If so, how do I trigger it? If not, Is there any other way to display a YesNo messagebox from the server side?

As far as I can tell, unless I misunderstood, the solutions I was given or was refered to, handled cases where client side script fires the second button's event, but that's not what I'm looking for. I need the server side script to trigger the client side script/event.

Guy
  • 325
  • 1
  • 3
  • 18
  • There's a very good answer [here](http://stackoverflow.com/questions/2381572/how-can-i-trigger-a-javascript-event-click) by [Juan Mendes](http://stackoverflow.com/users/227299/juan-mendes). But if you like to take shortcuts, jQuery has a nice [trigger](http://api.jquery.com/trigger/) method :) – Ian Brindley Sep 28 '14 at 15:55
  • Do you mean you want to display a winform MedsageBox on the server side so the user can click Yes or No? Or you want to display a client "browser" message then fire an event on the server by using a hidden Asp.Net hidden button control? – Aladin Hdabe Sep 28 '14 at 16:06

1 Answers1

1

jQuery way

$('#button1').on('click', function(e){
    $('#button2').trigger('click');
});

JavaScript way

var button1 = document.getElementById('button1'),
    button2 = document.getElementById('button2');

button1.addEventListener('click', function(){
    var e = document.createEvent('HTMLEvents');
    e.initEvent('click', true, false);
    button2.dispatchEvent(e);
});
MaximOrlovsky
  • 265
  • 2
  • 8