Saturday, March 24, 2012

call codebehind onclick function from modal popup

My modal popup extender pops up an asp:panel that has a couple asp:textbox'es and an OK asp:button that I designate as the OKControlID. I've implemented a javascript function called OnOK() that's designated as the OnOkScript in my control extender, and also implemented a Button_Click function for the OK Button in my page codehind. How do I get the codebehind function to get called. My code calls the onOK script and stops.

Thanks!

Short answer:

You can't. The behavior adds a handler for the click event of the button which executes the OnOkScript(). This prevents a postback from occurring, and a postback is what you need to occur in order to call your code behind function.

Long answer: If you use the property "EnablePageMethods='true'" in your script manager, and assign [WebMethod] attribute to your codebehind, you can call that codebehind method from your JS OnOK function.


LSU:

Tried leaving a message for you on your listed website, but it

doesn't allow anonymous comments, and I didn't want to have to

sign up..I have need for this threads concepts, but I tried doing

an MPE.show in my code behind trying to get the MPE to

display as a result of running code, (not a button click) and

get a runtime error.."cmdDelete already has a data item registered."

VS2005 Pro has no problem with the code..am I using it out of

context?..what am I doing wrong?..

Thanks..


LSU.Net:

Short answer:

You can't. The behavior adds a handler for the click event of the button which executes the OnOkScript(). This prevents a postback from occurring, and a postback is what you need to occur in order to call your code behind function.

Long answer: If you use the property "EnablePageMethods='true'" in your script manager, and assign [WebMethod] attribute to your codebehind, you can call that codebehind method from your JS OnOK function.

Haha! Both answers looked "short" to me.Big Smile
It may not work for the poster's case since the CodeBehind is a WebMethod hence static method which is independent from the page object concept and so if there're reference to the page's objects in the code-behind it'll fail. For the original poster, you may have to "cheat" your way to get it to work. Please see this threadhttp://forums.asp.net/thread/1669503.aspx . I hope there'll be support from AJAX client side or we may have to extend the ModalPopup extender.Big Smile


G20:

Thanks for your input ! I haven't had time to read /absorb the details of the

link yet, but will today. George Bernard Shaw said:

"Science is always wrong. It never answers one question without asking

10 more."

Themodal.hide works fine from the code behind.

Themodal.Show is syntactically acceptable in the code behind,

but doesn't. Why? Where is it used? What is it supposed to do?

.Show works fine in my VB / Access apps (ha ha!)

Seriously, I've been looking for a comprehensive source for

the props & methods of AJAX controls..with examples, like

MSDN would be awesome. Then I could be self -reliant.

Any help there?


yeah i have the same problem as you.

I need to fire/call the modalpopup when there is a textchanged event in a textbox.

I have tried everything i can think of jscript wise.

I also dont' get why the modalpopupextender1.show() isn't working...

If you get this figured out could you please post it ? Ill do the same if i can figure it out.

Thanks

No comments:

Post a Comment