-- Master Page
-- Page
-- User Control
-- RadGrid
In the user control the component structure is like this:
-- <div>
-- <ajax:ModalPopupExtender>
-- <asp:Panel>
-- <telerik:RadGrid>
In my user control's Page_Load method, I have something like:
protected
void
Page_Load(
object
sender, EventArgs e)
{
LinkButton myLinButton = myMasterTemplate.MyButton;
myLinkButton.Click += myLinkButton_Click;
if
(Page.IsPostBack)
myGrid.NeedDataSource += myGrid_NeedDataSource
...(more code)
}
What happens is when I click on the link button the modal window will show up which contains the grid. It works fine except the user control's Page_Load event fires twice. If I comment out the line "myGrid.NeedDataSource += myGrid_NeedDataSource " then it's fine but of course I can't do that. This leads me to believe, internally, NeedDataSource is causing another postback. Is this correct? If so, is there any way to prevent this from happening?
Thanks.
16 Answers, 1 is accepted
Try attaching the event handler as follows:
protected void Page_Init(object sender, EventArgs e)
{
myGrid.NeedDataSource
+= new GridNeedDataSourceEventHandler(myGrid_NeedDataSource);
}
Hope it helps.
Best wishes,
Tsvetoslav
the Telerik team
1. Does NeedDataSource (which I assume internally it's also calling DataBind()) always fire a postback?
2. If so, is there any way to prevent such behavior?
Thanks.
RadGrid does not internally make post-backs on any event - therefore the reason lies elsewhere. Please, open a formal support ticket and attach your files for us to investigate the issue. Thanks for that.
Best wishes,
Tsvetoslav
the Telerik team
What we have seen, this only seem to happen if you apply a filter, but NOT if you choose "No filter" as filter option (in case it will only databind once). Also, we have the feeling that this occours much more frequently with AJAX than without.
Make sure that you are using Advanced data-binding and not simple data-binding. If you have done so, please, provide your code.
Regards,Tsvetoslav
the Telerik team
I'm confused, I mentioned in the post before you that we experienced the same situation both with DataBind() (simple data binding) and NeedDataSource (Advanced Data Binding), so I don't understand your question? Also, are you saying that the Simple Data Binding is broken and should not be used?
A side note...I seem to remember having read something about having a drop down as a filter could cause multiple selects to fire, but I can't seem to find this info now. Does it ring a bell with anyone?
We are using DotNetNuke as our CMS, which mean that all functionality should be implemented as user controls, which is no problem. However, when using the RadTabStrip/RadMultiPage to build our module navigation, we have implemented this as more user controls, one per PageView. This mean we have nestled user controls, and for some still unknown reason, this seem to trigger multiple Page_Loads to be fired, not only one per user control, but in fact twice per user control. This will of course also fire multiple DataBinds/NeedDataSource in RadGrid. We also tried to add a standard MS GridView to the nestled user control, and it behaved the same, multiple DataBinding events.
I would guess that this could be a problem facing many developers using Telerik/DotNetNuke, of which some perhaps are unaware of this as it won't really show unless you starts looking into performance problems etc. We are currently investigating how to solve this, but if anyone has some great ideas how to work this out, please share.
The RadGrid in our user control has a client event hooked up to a js function which sends a AjaxRequest to simulate a row click when the page is shown so that related detail information will also display. The problem is AjaxRequest is actually a postback so when the following events occur:
1. Control's Page_Load
2. Page's Page_Load
3. Control's AjaxRequest
4. Page's Page_Load
I don't know if your situation is similar but i guess something somewhere must be doing another postback.
Still without looking at your code it is difficult to determine what the cause for the trouble might be. What I had in mind by stressing the need to use Advance data-binding is that you should not have calls to the grid's DataBind() method anywhere in the code (only Rebind() should be used when the grid is to be repopulated). It's best if you open up a formal support ticket and send your files as an attachment.
Regards,Tsvetoslav
the Telerik team
I am using RadAjaxManager, Rad Grid and Rad Button and on Rad Button Click i am updating a record after successful update i want to rebind the grid without occurring page post back.. for this what i have to do??
You just need to call the grid's Rebind() method in the click event of the rad button. And do make sure that you have ajaxified the grid - the button should ajaxify RadGrid so that asynchronous request is made.
Regards, Tsvetoslav
the Telerik team
I am using RadAjaxManager and RadAjaxLoadingPanel with RadGrid. On grid column i have asp linkbutton and on that link button click i am calling one javascript function..
everything is working fine but on that link button click i am not able to show loading panel and also post back occurs :(
below is my code :
ajax setting is :
<telerik:AjaxSetting AjaxControlID="lnkbtnDownload">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="rg_Attachments" LoadingPanelID="tlkRadAjaxLoadingPnl" />
</UpdatedControls>
</telerik:AjaxSetting>
On Grid i have asp link button on GridTemplateColumn like:
<telerik:GridTemplateColumn HeaderText="Download">
<ItemTemplate>
<asp:LinkButton ID="lnkDownload" runat="server" Text="Download" OnClientClick="return downloadpdf(id);"
ForeColor="Blue"></asp:LinkButton>
</ItemTemplate>
</telerik:GridTemplateColumn>
and this is my javascript function:
<script language="javascript" type="text/javascript">
function downloadpdf(id) {
var annid = id.replace("lnkDownload", "annId");
window.location = "DownloadAttachment.ashx?id=" + document.getElementById(annid).value;
return false;
}
</script>
Please help........
You are effectively making a post back since the javascript calls redirects to an http handler to download a file - that's the reason why the loading panel is not showing. Your scenario is a bit tricky but you can still work around it as demonstrated in the following code library:
http://www.telerik.com/community/code-library/aspnet-ajax/grid/show-loading-panel-when-exporting-radgrid.aspx
The code library is implemented for an export but it is essentially the same set-up as in your case and it should be easy for you to adapt it to your implementation.
Hope it helps.
Regards, Tsvetoslav
the Telerik team
I have a similar issue where I am binding the Radgrid on the click of a button.The NeedDataSource considers even the button click as a postback and is fired twice every time. This happens both for events inside the grid and outside like the button click. How can I avoid this and make sure the button click does not call the needdatasource.
Please make sure that you are calling the Rebind() method of the grid only after the click event handler of the button and you don't have genuine DataBind() or Rebind() anywhere else:
http://docs.telerik.com/devtools/aspnet-ajax/controls/grid/defining-structure/changing-the-grid-structure-dynamically-on-postback
Hope this helps.
Regards,
Eyup
Telerik