Link to home
Start Free TrialLog in
Avatar of Roberta Franchi
Roberta Franchi

asked on

javascript user control

Hello,

I have an ascx user control and two instances of user control on the same aspx page.

I would like to add javascript to manage the postback of a button inside the user control in order to show a waiting icon and disable the button  while execution.

The following javascript is working well ONLY if there is just one instance of the user control on the page but if there are two or more instances,  the javascritpt is executed but in the first instance of the user control created on the page. (I mean, i I click the button of the second user control on page, the button disabled is the one of the first user control and also the <div> is shown in the first user control.

The javascript is the following:

// Get the instance of PageRequestManager.
var prm = Sys.WebForms.PageRequestManager.getInstance();
// Add initializeRequest and endRequest
prm.add_initializeRequest(prm_InitializeRequest);
prm.add_endRequest(prm_EndRequest);

// Called when async postback begins
function prm_InitializeRequest(sender, args) {
// get the divImage and set it to visible
var panelProg = $get('divImage');
panelProg.style.display = '';

// Disable button that caused a postback
$get(args._postBackElement.id).disabled = true;
}

// Called when async postback ends
function prm_EndRequest(sender, args) {
// get the divImage and hide it again
var panelProg = $get('divImage');
panelProg.style.display = 'none';

// Enable button that caused a postback
$get(args._postBackElement.id).disabled = false;
}

Open in new window


I've tried to put this javascript code inside the web user control but...no way.
Also tried to put it inside the aspx page... but no way.


Thanks
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Have you considered using JQuery for this?
<script src="http://code.jquery.com/jquery.js"></script>
<script type="text/javascript">
$(function() {
   $('.buttonClass').click(function() {
       var control = $(this);
       $.ajax({
            url: urltosendto,
            data: datatosend,
            type: 'POST',
            success: function(response) {
                 // interact with control or other elements here
            }
       });
   });
});
</script>

Open in new window

Avatar of Roberta Franchi
Roberta Franchi

ASKER

where do I have to put it? in the ascx or aspx?
Which is the reason why this JQuery will work instead of mine?
thanks
solution is not working
not working.....not working not working not working
ASKER CERTIFIED SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial