This is a migrated thread and some comments may be shown as answers.

Avoid Grid_NeedDataSource call if Response.Redirect is called previously

1 Answer 64 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Andy
Top achievements
Rank 1
Andy asked on 05 Jan 2017, 11:26 AM

I have a Telerik RadGrid within a .ascx (user control) that requires a *_NeedDataSource method to populate the grid's DataSource.

The same user control is doing some user authentication, simply checking HttpContext.Current.User.Identity.IsAuthenticated and doing a Response.Redirect(url, false) if it is false.

I'm seeing exceptions being raised on our live system due to the *_NeedDataSource method being called when the user is not logged in, this seems to be possible because I pass false as the value of the endResponse parameter to Response.Redirect. The original author coded it this way as I assume he was going on the guidance of the community:

  1. http://stackoverflow.com/questions/947197/using-endresponse-in-a-response-redirect
  2. https://blogs.msdn.microsoft.com/tmarq/2009/06/25/correct-use-of-system-web-httpresponse-redirect/

I've been trying to work out a way that I can reliably prevent execution of *_NeedDataSource without reverting to an endResponse value of true.

I can think of some ways which involve flag setting and checking but that seems inelegant and subsequent developers could forget to implement the same pattern. I've also tried implementing a base control type to derive from which overrides OnPreRender (or whatever), similar to the response from Spongeboy to this question: ASP.NET Redirect and End Page but I cannot work out the method to override that will prevent execution of *_NeedDataSource.

Can anyone recommend an approach that would work in this situation and wouldn't require too much cognitive overhead?

Apologies, egregiously copied from http://stackoverflow.com/questions/41483271/avoid-grid-needdatasource-call-if-response-redirect-is-called-previously

1 Answer, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 09 Jan 2017, 01:26 PM
Hello Andy,

I have gone through your description of the scenario and using a flag variable is the only option that you have for achieving the desired behavior (this applies not only for the OnNeedDataSource event, but to any other event, so it is not directly linked to the RadGrid control).


best Regards,
Konstantin Dikov
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
General Discussions
Asked by
Andy
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Share this question
or