.NET Discussion

.NET Issues, Problems, Code Samples, and Fixes

ASP.NET and Javascript: Accessing Server Side Code?

While writing some code today, I had an idea to improve user experience with a smidge of Javascript. Basically, click on a picture to show its enlarged version (using a ModalPopupExtender), and then on close, run some Javascript to have the appropriate radio button be selected for the image the user just looked at.  No problem, two lines of Javascript, and I don’t even know it that well (although, ASP.NET makes it a pain in the arse to match up control ID’s since they mangle them at run time.  If you’re having problem with ASP.NET changing control ID’s, run your app and check the source code.  Usually your control’s ID is something like “ctl00_somePanel_yourControlID”). 

However, I wanted to run some additional events when certain radio buttons were selected, like hiding or showing certain other panels.  This is easy on the back end, but since I’m already running the ModalPopupExtender, the server side “OnClick” event for the button doesn’t actually fire.  Rather than write some more Javascript to cover all the different permutations of possibilities that could occur, I would rather invoke the server side code once the Javascript has stopped running.  I found this article about Remote Scripting at the Code Project, but it seems far too complex for what I want to do.

Anyone have any ideas on how to call server side code via Javascript?  Or should I just suck it up and have my viewers suffer a postback?  Or better yet, is there a way to get the “OnCheckedChanged” (for the radio button) event to fire from the Javascript, rather than actually calling the server side code?


August 20, 2007 - Posted by | ASP.NET, Javascript, ModalPopupExtender


  1. Hey, I just read this and I had the same problem. I think it’s because you are trying to use the OkButton to do something server side but also to do something on the client side. I got around it by having a hidden button on the page for the extender okcontrol and then calling the hide() from codebehind and then doing the server side stuff

    This is the code that would hide the modal

    Hope it helps

    Comment by Jon | January 1, 2008 | Reply

  2. can you paste the code, i need some help here.
    i am showing extender modal popup and on the popup control there are 2 link buttons, i need to do some thing on the server side when any one clicked on the buttons…The problem is after anyone clicked on it the popup is not showing on the page, so i used popup.show in the button click event. Finally i got it work, the problem is it is hiding after i clicked the button and loading or showing again after response form the server, in the sense some flickering is coming on the page.. But i don’t need that. no flickering needed. is there any way to show the popup without hiding and showing even link button present on the popup panel?

    Comment by praveen battula | July 21, 2008 | Reply

  3. hello guys

    when i run the asp.net application,the button control in my page,gets enlarged, i dnt know how to avoid that

    let me know

    Comment by rajesh | March 1, 2009 | Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: