Wednesday, March 28, 2012

Linkbutton inside atlas:UpdatePanel

Hi All,

I am having few linkbuttons inside an atlas:UpdatePanel. I have placed these inside UpdatePanel as I have to regularly change the text of this linkbuttons.

When I click on these linkbuttons it is actually supposed to update a DataGrid which is placed outside atlas:updatepanel, but in same page. When I debug and see, the Onclick code for the Linbutton is called and also the code necessary to update the Datagrid is also executed. But for some reason, in display the Datagrid is not changing. Is this got something to do with the positioning of grid in page? it is outside updatepanel.

I will copy the required parts of code here . Please help.

In aspx page :

<atlas:TimerControl ID="tmrUpdate" runat="server" Enabled="true" Interval="300000" OnTick="SetIndicatorCount"></atlas:TimerControl>
<atlas:UpdatePanel ID="pnlUpdate" RenderMode="Inline" runat="server">
<ContentTemplate>
<table style="background-color:whitesmoke;font-size:smaller" cellpadding="2" cellspacing="0">
<tr class="DisplayHeader">
<td class="DisplayHeader" colspan="4" align="left">
<asp:Label ID="Label2" runat="server" Text="Driver Exceptions"></asp:Label>
</td>
</tr>
<tr>
<td style="height: 19px">
<cc1:LinkButton ID="lnkTrainersAvailable" Text = "Trainers Available" runat="server" OnClick="lnkTrainersAvailable_Click" ></cc1:LinkButton>
</td>
<td style="height: 19px">
<cc1:LinkButton ID="lnkServiceExceptions" Text="Service Exceptions" runat="server" OnClick="lnkServiceExceptions_Click"></cc1:LinkButton>

</td>
<td style="height: 19px">
<cc1:LinkButton ID="lnkUnreadMessages" Text = "Unread Messages" runat="server" OnClick="lnkUnreadMessages_Click"></cc1:LinkButton>
</td>
<td style="height: 19px">
<cc1:LinkButton ID="lnkHoursNotIn" Text="Hours Not In" runat="server" OnClick="lnkHoursNotIn_Click" ></cc1:LinkButton>
</td>
</tr>

<tr>
<td>
<cc1:LinkButton ID="lnkDriversAvailable" Text = "Drivers Available" runat="server" OnClick="lnkDriversAvailable_Click"></cc1:LinkButton>
</td>
<td>
<cc1:LinkButton ID="lnkContactDue" Text = "Contacts Due" runat="server" OnClick="lnkContactDue_Click" ></cc1:LinkButton>

</td>
<td>
<cc1:LinkButton ID="lnkMaintenanceDue" Text = "Maintenance Due" runat="server" OnClick="lnkMaintenanceDue_Click" ></cc1:LinkButton>
</td>
<td>
<cc1:LinkButton ID="lnkFreeTimeExpired" Text = "Free Time Expired" runat="server" OnClick="lnkFreeTimeExpired_Click" ></cc1:LinkButton>
</td>
</tr>
<tr>
<td style="height: 19px">
<cc1:LinkButton ID="lnkMissedCalendars" Text = "Calendar Due" runat="server" Enabled="true" OnClick="lnkMissedCalendars_Click"></cc1:LinkButton>
</td>
<td style="height: 19px">
<cc1:LinkButton ID="lnkDriverWorkflowRequired" Text = "Driver Workflow Req." runat="server" Enabled="false"></cc1:LinkButton>
</td>
<td style="height: 19px">
<cc1:LinkButton ID="lnkTrackingEarly" Text = "Tracking Early" runat="server" OnClick="lnkTrackingEarly_Click" ></cc1:LinkButton>
</td>
<td style="height: 19px">
<cc1:LinkButton ID="lnkCurrentDeliveries" Text="Current Deliveries" runat="server" OnClick="lnkCurrentDeliveries_Click" ></cc1:LinkButton>
</td>
</tr>
<tr>

<td>
<cc1:LinkButton ID="lnkDetention" Text = "Detention Pay" runat="server" OnClick="lnkDetention_Click"></cc1:LinkButton>
</td>
<td>
<cc1:LinkButton ID="lnkSafteyFollowUp" Text = "Safety Follow up/Audit" runat="server" Enabled="false"></cc1:LinkButton>

</td>
<td>
<cc1:LinkButton ID="lnkTrackingLate" Text = "Tracking Late" runat="server" OnClick="lnkTrackingLate_Click" ></cc1:LinkButton>
</td>
<td>
<cc1:LinkButton ID="lnkDiaryFollowUp" Text = "Diary Follow Up" runat="server" OnClick="lnkDiaryFollowUp_Click"></cc1:LinkButton>
</td>


</tr>
</table>
</ContentTemplate>
<Triggers>
<atlas:ControlEventTrigger ControlID="tmrUpdate" EventName="Tick" />
</Triggers></atlas:UpdatePanel>
<tr>
<td colspan="2">
<uc1:grdDriverCurrentInformationDisplay ID="_grdDriverCurrentInformationDisplay" runat="server" ></uc1:grdDriverCurrentInformationDisplay>
</td>
</tr>

Actually the grid is inside the User control, grdDriverCurrentInformationDisplay.

In aspx.cs the code for Linkbutton clicks which are inside updatepanel are there :

protectedvoid lnkHoursNotIn_Click(object sender,EventArgs e)

{

try

{

lblDrivers.Text ="Hours Not in Drivers ";this.LoadDriverIndicators(RTI.DataLayerV2.RTIDriver.DMDriverIndicator.MessagingIndicatorTypeEnum.HoursNotIn);

}

catch (RTI.FrameworkV2.BrokenRulesException bex)

{

this.Messages = bex.Messages;

}

}

////One method used to retreive the information for the supervisor codes, where clause and indicator typepublic void LoadDriverIndicators(RTI.DataLayerV2.RTIDriver.DMDriverIndicator.MessagingIndicatorTypeEnum indicatorType) {//retrieves the correct supervisorcodes and the where cluase from the grid where they stored in a hidden text boxstring supervisor =this._grdDriverCurrentInformationDisplay.GetSupervisorCode();string whereClause =this._grdDriverCurrentInformationDisplay.GetWhereClause();if (String.IsNullOrEmpty(supervisor))throw new Exception("Must enter a supervisor code");//If the messages are choosen it loads the drivers with unreadmessages from the communication system //otherwise the indicators are loaded from the driver database //Each time a link button is clicked the information is retrieved nothing is stored in view state RTI.Business.DriverManagement.DriverInfo.DriverIndicator indicator =new RTI.Business.DriverManagement.DriverInfo.DriverIndicator(); List indicatorList =new List();if (indicatorType == RTI.DataLayerV2.RTIDriver.DMDriverIndicator.MessagingIndicatorTypeEnum.UnreadMessages) { indicatorList = FleetManager.FillGrid.GetDriverInformationRows(indicator.LoadDriverInformationForUnreadMessage(supervisor, whereClause, RTI.CommonV2.Constants.CommunicationMessageCodes.FreeForm)); }else if (indicatorType == RTI.DataLayerV2.RTIDriver.DMDriverIndicator.MessagingIndicatorTypeEnum.ServiceExceptions) { indicatorList = FleetManager.FillGrid.GetDriverInformationRows(indicator.LoadDriverInformationForServiceExceptions(supervisor, whereClause)); }else if (indicatorType == RTI.DataLayerV2.RTIDriver.DMDriverIndicator.MessagingIndicatorTypeEnum.DiaryFollowUp) { indicatorList = FleetManager.FillGrid.GetDriverInformationRows(indicator.LoadDriverInformationForDiaryFollowup(supervisor, whereClause)); }else { indicatorList = FleetManager.FillGrid.GetDriverInformationRows(indicator.LoadDriverInformationAndIndicator(supervisor, whereClause, indicatorType));if (indicatorType == RTI.DataLayerV2.RTIDriver.DMDriverIndicator.MessagingIndicatorTypeEnum.TrackingLate) { indicatorList.Sort(delegate(FleetManager.FillGrid.DriverInformation d1, FleetManager.FillGrid.DriverInformation d2) {return d1.LateMinutes.CompareTo(d2.LateMinutes); }); indicatorList.Reverse(); } }this._grdDriverCurrentInformationDisplay.ClearGrid();if (indicatorList.Count > 0) { RTI.Business.DriverManagement.DriverInfo.DriverIndicator indicators =new RTI.Business.DriverManagement.DriverInfo.DriverIndicator(); RTI.DataLayerV2.RTIDriver.DMIndicatorCountDataTable table = indicators.LoadIndicatorCount(supervisor, whereClause);for (int k = 0; k < table.DataTable.Rows.Count; k++) { table.Index = k;if (table.IndicatorType == Convert.ToInt32(RTI.DataLayerV2.RTIDriver.DMDriverIndicator.MessagingIndicatorTypeEnum.HoursNotIn)) {if (indicatorType == RTI.DataLayerV2.RTIDriver.DMDriverIndicator.MessagingIndicatorTypeEnum.HoursNotIn) {int hoursCount = 0;for (int i = 0; i < indicatorList.Count; i++) {if (indicatorList[i].HomeCity.ToString().Trim().Replace(" ",string.Empty).Trim() == indicatorList[i].DestinationLocation.ToString().Trim().Replace(" ",string.Empty).Trim()) { indicatorList.Remove(indicatorList[i]); i--; hoursCount++; } }//RTI.Business.DriverManagement.DriverInfo.DriverIndicator indicators = new RTI.Business.DriverManagement.DriverInfo.DriverIndicator(); //RTI.DataLayerV2.RTIDriver.DMIndicatorCountDataTable table = indicators.LoadIndicatorCount(supervisor, whereClause);int count = Convert.ToInt32(table.Total) - hoursCount; lnkHoursNotIn.Text = String.Format("Hours Not In ({0})", count); } } }this._grdDriverCurrentInformationDisplay.LoadByDriver(indicatorList, indicatorType);this.lblDrivers.Text += indicatorList.Count.ToString(); }else {this.AddFeedbackMessage("There are no Drivers that qualify for the indicator"); } }

Please tell why the grid is not updated.

Regards,

Allen.

It's not getting updated because it's not in an updatepanel, and ithe page is not doing a full postback. Read up on update panels at ajax.asp.net/docs to see how the partial page rendering model works.


Is it that I have to include the user control which is having the DataGrid also inside The atlas:UpdatePanel? As Linkbutton's functionality is entirely different why is it required that grid also be in the Updatepanel. It's not a problem even if the entire page refreshes on click of linkbutton.

Please advise.


No, it doesn't have to be in the same updatepanel, just *an* updatepanel. your other option is to set the linkbutton up as a postback control (which tells the updatepanel to go ahead and post the whole page back even though it's inside the updp).


Enabling Partial-Page Updates

TheUpdatePanel control requires aScriptManager control in the Web page. By default, partial-page updates are enabled because the default value of theEnablePartialRendering property of theScriptManager control istrue.

The following example shows markup that defines aScriptManager control and anUpdatePanel control on a page. TheUpdatePanel control contains aButton control that refreshes the content inside the panel when you click it. By default, theChildrenAsTriggers property istrue. Therefore, theButton control acts as an asynchronous postback control.

You have to set LinkButtons PostBack property, so it postbac the page.

http://ajax.asp.net/docs/overview/UpdatePanelOverview.aspx

No comments:

Post a Comment