Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ClientScriptManager.GetPostBackEventReference Method

I'm trying to understand what this method means as I'm reading this and have wondered what uses this may have. I don't quite understand the example given.

Can anyone give another explanation of it. Examples would help.

Thanks

like image 225
Brian Liang Avatar asked Nov 05 '08 22:11

Brian Liang


2 Answers

The simplest example is a LinkButton. Drop one in a page and look at the HTML it generates. You'll see something like.

href="javascript:__doPostBack('ctl00$LinkButton1','')"

GetPostBackEventReference allows you to get that piece of JavaScript, so that you can trigger that postback from elsewhere. However you run that bit of JavaScript, a postback will happen and the OnClick event will fire on the server just as if you'd clicked the LinkButton. The example on MSDN wires up a similar bit of JavaScript to the links to trigger server-side events on the GridView.

The more practical uses are when you want to handle postbacks in a custom control. Your control implements IPostBackEventHandler to handle the postbacks on the server, and you use GetPostBackEventReference to get the JavaScript that will trigger those postbacks.

like image 144
stevemegson Avatar answered Sep 19 '22 01:09

stevemegson


As steve mentioned this can be used for

GetPostBackEventReference allows you to get that piece of JavaScript, so that you can trigger that postback from elsewhere.

To give an example, you can use this function to get reference to PostBack event of button click and add it to onblur of a textbox.

This would simulate the button click whenever the textbox looses the focus.

like image 3
Ramesh Avatar answered Sep 22 '22 01:09

Ramesh