[RESOLVED]get id of an asp.net dropdownlist that causes the postback

I’m trying to use the following:

function InitializeRequest(sender, args) {
            var postBackElement = $get(args._postBackElement.id);
            if (postBackElement != null) {
                postBackElement.disabled = true;
                oldClass = postBackElement.className;
                postBackElement.className = postBackElement.className + " disabled";
            }
        }

but args._postBackElement.id is not working for DropDownList but only for button. How can I get the ID of a DropDownList causing the postback?

Thanks

Hi RobFra,

Thanks for your post.

RobFra

function InitializeRequest(sender, args) {
            var postBackElement = $get(args._postBackElement.id);
            if (postBackElement != null) {
                postBackElement.disabled = true;
                oldClass = postBackElement.className;
                postBackElement.className = postBackElement.className + " disabled";
            }
        }

Firstly, when do you call this function?

Secondly, you could show us your complete code, then we will test your code and try our best to fix it.

Best Regards,

Fei Han

Hello Frei,

the complete script is the following and it is called inside an ascx user control:

<%–<script type="text/javascript">
// 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 = true;
}
</script>–%>

I want to change the button that causes the postback to a dropdownlist. But I don’t find how to get the ID because args._postBackElement.id seems to work only for buttons.

Thanks

Hi RobFra,

If you’d like to retrieve post back control ID, you could refer to following link.

Hope it will be helpful to you.

Best Regards,

Sw-ing

Leave a Reply