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
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With