Showing posts with label aspx. Show all posts
Showing posts with label aspx. Show all posts

Monday, March 26, 2012

Trigger not working for Linkbutton in GridView

I have a linkbutton I'm trying to add a trigger two for two update panels on my aspx page.

I have this but the update panels are not updating... any recommendations?

protected void GridView_ChangeSearchResults_RowDataBound(object sender, GridViewRowEventArgs e) {if (e.Row.RowType == DataControlRowType.DataRow) { LinkButton lb = (LinkButton)e.Row.FindControl("Linkbtn_StaffChangeNew"); AsyncPostBackTrigger trigger =new AsyncPostBackTrigger(); trigger.ControlID = lb.UniqueID.ToString(); trigger.EventName ="Command"; UpdatePanel_Header.Triggers.Add(trigger); UpdatePanel_Info.Triggers.Add(trigger); } }

It doesn't bomb out on me and I've put in a breakpoint and is seems to be adding the triggers but they don't fire for some reason. When I add the triggers in from the GUI I'm using the onlcick event for other button controls on the page.

For this action I am using a command event. I've tried changing the EventName to both Click and Command and neither seem to work. Here is the method for the command event.

protected void ChangeStaffFromGrid(object sender, CommandEventArgs e) {int userStaffID = Convert.ToInt32(bmsUser.CmsStaffID);string budgetyear = Convert.ToString(budgetYear.UserSelectedFiscalYear);
int profileID = Convert.ToInt32(Session["staffProfileID"]);int newProfileID = 0;int newStaffID = Convert.ToInt32(e.CommandArgument);//sets the new staff ID from the selection. Hashtable changeStaffHash =new Hashtable(); changeStaffHash = BmsDLL.ChangeStaff(profileID, newStaffID, userStaffID); newProfileID = Convert.ToInt32(changeStaffHash["newStaffProfileID"]); SetUserSessions("change", newProfileID); SetHeaderInfo(Convert.ToInt32(Session["staffProfileID"])); SetNewProfileIDItems(Convert.ToInt32(Session["staffProfileID"])); }

The two methods that update the two pannels are SetHeaderInfo and SetUserSessions.

Thanks for your help.

Use ScriptManager1.RegisterAsyncPostBackControl(YourLinkButton) instead of creating AsyncTrigger. then in the button command event update your update panels by calling the update.


I've just recenlty started using Ajax in my app, do you have a code example of your suggestion?

Which even would I add ScriptManager1.RegisterAsyncPostBackControl(YourLinkButton) ? In the rowdatabound event?


Try the following code:

protected void GridView_ChangeSearchResults_RowDataBound(object sender, GridViewRowEventArgs e){if (e.Row.RowType == DataControlRowType.DataRow) { LinkButton lb = (LinkButton)e.Row.FindControl("Linkbtn_StaffChangeNew");ScriptManager1.RegisterAsyncPostBackControl(lb);// Assuming the ScriptManager name in your page is ScriptManager1 }}

That didn't work. The same updates to the panels are working with regular buttons. This makes no sense.


Hi,

As far as I know,You can add anUpdatePanel control programmatically, but you cannot add triggers programmatically. To create trigger-like behavior, you can register a control on the page as an asynchronous postback control. You do this by calling theRegisterAsyncPostBackControl(Control) method of theScriptManager control. You can then create an event handler that runs in response to the asynchronous postback, and in the handler, call theUpdate() method of theUpdatePanel control.

For more information,seehttp://www.asp.net/AJAX/Documentation/Live/mref/T_System_Web_UI_UpdatePanel.aspx

IfRegisterAsyncPostBackControl(Control) method & Update() method doesn't work, there must be something wrong in your code.You can post some code so we can check out where is the error.

Best Regards


It seems the Update() method is working for me. Thanks for your help.

Saturday, March 24, 2012

Triggering an Updatepanel (b) based on a gridview rowcommand which is inside a UpdatePanel

Hi there,

I have two sections on my aspx page which contain two grids on an aspx page. User and UserDetails.

User section has atab control which contains an update panelupUsers which contains the gridviewgvUsers. I have another grid in a different updatepanelupUserDetails this contains a grid toogvUserAccessKeys. I want to refresh the second updatepanelupUserDetails (basically trigger it) based on the RowCommand in the gvUsers which is in the first update panel. I was able to do this till I added the tab control.

Now it cannot find the gvUsers controlID when I write the trigger.

So is it possible to trigger a different UpdatePanel based on a gridview Control rowcommand event from inside a AjaxControlKit tab control.

Thanks in advance for any suggestions.

Rakesh Ajwani

following is the HTML snipped of the aspx page.

</td><tdstyle="width: 100px"valign="top"><cc1:TabContainerID="pTabs"runat="server"ActiveTabIndex="0"><cc1:TabPanelrunat="Server"ID="tabUsers"HeaderText="Users"Enabled="true"><ContentTemplate><asp:UpdatePanelID="upUsers"runat="server"><ContentTemplate><asp:GridViewID="gvUsers"runat="server"AutoGenerateColumns="False"Width="129px"OnRowDataBound="gvUsers_RowDataBound"OnRowCommand="gvUsers_RowCommand"><Columns><asp:TemplateFieldHeaderText="Users"><HeaderTemplate><tablewidth="100%"><tr><tdalign="left"><asp:Labelrunat="server"Text="Users"></asp:Label></td><tdalign="right"><asp:ImageButtonID="ibAddUser"OnClick="ibAddUser_Click"runat="server"ImageUrl="Images/plus-8.png"/></td></tr></table></HeaderTemplate><ItemTemplate><asp:LinkButtonrunat="server"ID="linkbUserSelect"Text='<%#((System.Data.DataRow)Container.DataItem)["LastName"] + " " + ((System.Data.DataRow)Container.DataItem)["FirstName"]%>'CommandName="ViewDetail"></asp:LinkButton></ItemTemplate></asp:TemplateField></Columns></asp:GridView></ContentTemplate><Triggers><asp:AsyncPostBackTriggerControlID="gvInstitutions"EventName="RowCommand"/></Triggers></asp:UpdatePanel></ContentTemplate></cc1:TabPanel></cc1:TabContainer></td></tr><tr><tdcolspan="2"width="100%"><asp:UpdatePanelID="upUserDetail"runat="server"><ContentTemplate><asp:LabelID="lblInstitution"runat="server"Width="132px"></asp:Label><br/><br/><asp:LabelID="lblLName"runat="server"Width="143px"></asp:Label><asp:TextBoxID="txtLName"runat="server"Width="143px"></asp:TextBox><asp:LabelID="lblFName"runat="server"Width="143px"></asp:Label><asp:TextBoxID="txtFName"runat="server"Width="143px"></asp:TextBox>

<br/><br/><asp:LabelID="lblEmailID"runat="server"Width="154px"></asp:Label><asp:TextBoxID="txtEmailID"runat="server"Width="143px"></asp:TextBox><br/><asp:GridViewID="gvAccessKeys"runat="server"AutoGenerateColumns="False"Width="689px"OnRowCreated="gvAccessKeys_RowCreated"OnRowDataBound="gvAccessKeys_RowDataBound"><Columns><asp:TemplateFieldHeaderText="Application"><ItemTemplate><asp:LabelID="lblApplication"runat="server"Visible="true"Text='<%#((System.Data.DataRow)Container.DataItem)["ApplicationCode"]%>'></asp:Label></ItemTemplate></asp:TemplateField><asp:TemplateFieldHeaderText="Institution"><ItemTemplate><asp:LabelID="lblCampus"runat="server"Visible="true"Text='<%#((System.Data.DataRow)Container.DataItem)["InstitutionName"]%>'></asp:Label></ItemTemplate></asp:TemplateField><asp:TemplateFieldHeaderText="Role"><ItemTemplate><asp:DropDownListID="ddRole"EnableViewState="true"runat="server"></asp:DropDownList></ItemTemplate></asp:TemplateField></columns><EmptyDataTemplate><tablewidth="100%"><tr><tdalign="left">Access Keys</td></tr><tr><tdcolspan="2"><asp:LabelID="lblNoUCARData"runat="server"Text="No Soup For You"Width="217px"></asp:Label></td></tr></table>

</EmptyDataTemplate></asp:GridView><asp:ButtonID="btnSave"runat="server"Text="Save & notify"OnClick="btnSave_Click"/></ContentTemplate><Triggers><asp:AsyncPostBackTriggerControlID="gvUsers"EventName="RowCommand"/></Triggers></asp:UpdatePanel></td></tr>

Hi,

I have a similar problem, except that I am loading UserControls with GridView dynamically into the TabPanels. The GridView have buttons that should fire RowCommand. The TabContainer is within an UpdatePanel. My RowCommand event is not firing, did you find any solutions to your problem?

Thanks.


Hook the gvUsers RowCreate Event, Find the Button using the FindControl. Once Found, create asyncpostbacktrigger programatically set the control id to the found button id and add the trigger in the second update panel trigger collection.

Triggers for update panel

I have a web page (aspx) that has on it 2 controls (ascx) - one of the controls has an update panel with functionality for it etc. - I want to trigger the update function from the second control that has a linkbutton on it.

Is this possible?

TIA

Yes. Update panel has Triggers element which can be used as follows
 <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <Triggers> <asp:AsyncPostBackTrigger ControlID="lnkButton" EventName="Click"/> </Triggers> </asp:UpdatePanel>

It would seem so - but if the trigger and the update panel are in different ascx files they can not see each other - even if those ascx files exist as controls on the same aspx page

You can explicitly call Update method of another UpdatePanel like this:

UpdatePanel1.Update() ;

Assumption: LinkButton is in UpdatePanel2 and the above code is written in event handler for LinkButton click event.

Generally, you have this kind of scenario in Master-Detail relationship. There is tutorial onhttp://ajax.asp.net site about this.


Okay I dont think you are looking at what the question says - because this doesnt work - unless you can point me to the specific tutorial I cant find the one you are talking about

here is a simple picture that diagrams what I am trying to do

Page1.aspx has two controls on it - both controls are ascx files (Control1.ascx and Control2.ascx)

Control1.ascx has an image button that when clicked is to trigger the UpdatePanel on Control2.ascx

Example