Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

GridView and AJAX 1

Status
Not open for further replies.

Premalm

Programmer
Mar 20, 2002
164
US
Hi,

I have a Gridview control which is under UpdatePanel control using AJAX.

When I click the Select button in the GridView the SelectedIndexChanged button is not getting triggered asynchronously.

It works fine if I remove the UpdatePanel Control but in that case it will do a PostBack and load the entire page.

I want to use AJAX and run the SelectedIndexChanged event asynchronously.

Any ideas ?

Thanks
Pr
 
If your markup looks like this
Code:
<asp:UpdatePanel ... ChildrenAsTriggers="true">
   <ContentTemplate>
      <asp:GridView ... OnSelectedIndexChanged="..." />
   </ContentTemplate>
</asp:UpdatePanel>
then the event is firing. If selectedindexchanged changes another part of the page this needs to be wrapped with an update panel as well. and have the trigger set to GridView.SelectedIndexChanged

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
You suggestion solved my problem.

I have one question. I have 5 controls which need to be updated when the Select button is updated. So I need to add 1 UpdatePanel for each of this controls. Is there any way around this ? Like just one single UpdatePanel for 5 controls.

Are there any performance issues if I have too many UpdatePanels ?

Thanks
Premal.


 
here is a good MSDN article on the UpdatePanel. Note: the UpdatePanel acutally performs a full postback, it just wraps it in an async call. So your preformance gain, if any) is mineute.

5 or 1 panels isn't a big deal.
if the data is readonly (no actions taken during postback) then a web service is your best bet for preformance.
if controls are grouped together and need to be updated together then I will wrap them in the same UpdatePanel. If they are not displayed together or do not require updates together then I will use seperate UpdatePanels

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
I have one more question.

I have a gridview with a Select button. When the user clicks the Select button, it should create a file and open it. When I put the gridview in a UpdatePanel it creats the file when the Select button is clicked but doesn't Show the file in the browser.

Any ideas ?

Thanks
Pr

 
are you redirecting to the file? I'm not sure how update panels deal with redirects.

your safest option is to register a startup script with the script manager to redirect. it would look something like this
Code:
protected void Gridview_SelectedIndexChanged(...)
{
   ... generate file
   ScriptManager.RegisterStartupScript(this, this.GetType(), "redirect", "window.location = '[url]';, true);
}

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
here is my code which shows the file.

string strScript = "<script language='javascript'> window.open('../data/" + sFile + "','mywin')</script>";
ScriptManager1.Page.ClientScript.RegisterStartupScript(this.GetType(), "PopupScript", strScript);

Thanks
Pr
 
this won't work because you call the scriptmanger from the page, not the scriptmanager for ajax operations.
instead you need to use the static scriptmanager which ties into the ajax script manager on the page.

copy the line of code in my previous post and alter the js as necessary.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top