Friday, December 5, 2008

Showing ModalPopUpExtender from Client Side

Just recently, I came across a situation where I needed to display a modal popup dialog box from my left navigation bar links.

Now the problem it had was all those links were actually Anchor (HREFs) and therefore they had a few problems in getting it to show the modal pop-up.

So here is how I finally got it done through Javascript...

This is the HREF that I created
<a href='' onclick='javascript:fncShowPopUp();return false;'>Edit Profile</a>
And here is what is required in the fncShowPopUp function:
function fncShowPopUp()
{
var popUpExtender = $find("ModalPopupExtender");
if(popUpExtender)
{
popUpExtender.show();
}
return false;
}

return false; is something that would actually stop the HREF from inducing a postback on the page, since if there is a post back, the Modal Popup would be hidden once again..

Njoy
-- Ashutosh

1 comment:

  1. Anonymous22:52

    looks easy but doesn't work. I think you should use the BehaviorID instead of the ID of the modal control.

    ReplyDelete