Showing posts with label displayed. Show all posts
Showing posts with label displayed. Show all posts

Monday, March 26, 2012

Detailsview in updatepanel with dropdownlist SelectedIndexChanged to update textbox(s) val

I am new to the updatepanel and need some help. I have a gridview control and a detailsview control. The detailsview control is displayed for edits on the gridview row select command. These controls are wrapped in an updatepanel, there are 2 textboxes that I want to update with calculated values based on the selected value of the dropdownlist. I was trying to accomplish this by using the SelectedIndexChanged of the ddlScheduleType dropdownlist in codbehind.

How do I get this to work, am I on the right track? Any help would be greatly appreciated, code is below.

Protected

Sub ddlScheduleType_SelectedIndexChanged(ByVal senderAsObject,ByVal eAs System.EventArgs)'Get a refernce to the dropdownlist:Dim ddlScheduleTypeAs DropDownList =CType(CType(sender, DetailsView).FindControl("ddlScheduleType"), DropDownList)Dim nDistroyDaysAsInteger = Utility.GetBoxCatDestroyDays(ddlScheduleType.SelectedValue)Dim ctrlTbDYAs TextBox =CType(CType(sender, DetailsView).FindControl("tbDestroyYear"), TextBox)Dim ctrlTbDMAs TextBox =CType(CType(sender, DetailsView).FindControl("tbDestroyMonth"), TextBox)Dim ctrlTbDEAs TextBox =CType(CType(sender, DetailsView).FindControl("tbDateEnd"), TextBox)

<%

@dotnet.itags.org.PageLanguage="VB"MasterPageFile="~/Default.master"AutoEventWireup="false"CodeFile="drEdit.aspx.vb"Inherits="drEdit"title="Untitled Page" %>

<%

@dotnet.itags.org.RegisterAssembly="AjaxControlToolkit"Namespace="AjaxControlToolkit"TagPrefix="ajaxtoolkit" %>

<%

@dotnet.itags.org.RegisterNamespace="CustomBoundField"TagPrefix="custom" %>

<

asp:ContentID="Content1"ContentPlaceHolderID="MainContent"Runat="Server">

<

ajax:ScriptManagerid="sm1"EnablePartialRendering="True"runat="server"/><table><tr><tdalign="Center"valign="Top"><ajax:UpdatePanelid="up2"runat="server"><contentTemplate><asp:GridViewRunat="server"Id="gvDrMaster"GridLines="Both"cellpadding="1"cellspacing="0"Headerstyle-BackColor="#BDCFE7"Headerstyle-Font-Names="Verdana,Helvetica,Arial;"Headerstyle-Font-Size="8"BackColor="#E7EFFF"Font-Names="Verdana,Helvetica,Arial;"Font-Size="8"BorderColor="Black"DataSourceID="SqlDsMaster"DataKeyNames="dr_id"AllowPaging="True"AllowSorting="True"PageSize="50"AutoGenerateColumns="False"><Columns><asp:CommandFieldShowSelectButton="True"/><asp:BoundFieldDataField="box_barcode"HeaderText="Barcode"/><asp:BoundFieldDataField="box_description"HeaderText="Description"HeaderStyle-HorizontalAlign=LeftItemStyle-HorizontalAlign=left/><asp:BoundFieldDataField="box_location"HeaderText="Location"/><asp:BoundFieldDataField="status_name"HeaderText="Status"/><asp:BoundFieldDataField="site_name"HeaderText="Site"/><asp:BoundFieldDataField="dr_id"ReadOnly="True"HeaderText=""HeaderStyle-Width="0"/><asp:BoundFieldDataField="box_site"ReadOnly=trueHeaderText=""HeaderStyle-Width="0"/></Columns><SelectedRowStyleBackColor=AliceBlue/></asp:GridView><triggers><ajax:controlValueTriggercontrolid="gvDrmaster"propertyname="Select"/></triggers></contentTemplate></ajax:UpdatePanel></td><tdalign="Left"valign="Top"><ajax:UpdatePanelid="up1"UpdateMode=Alwaysrunat="server"><contentTemplate><asp:DetailsViewDataKeyNames="dr_id"DataSourceID="SqlDsDetail"GridLines="Both"cellpadding="1"cellspacing="0"Headerstyle-BackColor="#BDCFE7"Headerstyle-Font-Names="Verdana,Helvetica,Arial;"Headerstyle-Font-Size="8"BackColor="#E7EFFF"Font-Names="Arial"Font-Size="8"BorderColor="Black"HeaderText="Author Details"AutoGenerateRows="False"HeaderStyle-Font-Bold="True"OnItemUpdated="DVAfterUpdate"ID="dvDrMaster"runat="server"><Fields><asp:BoundFieldDataField="dr_id"HeaderText="ID"ReadOnly="True"ControlStyle-CssClass="dvDataField"/><asp:BoundFieldDataField="box_barcode"HeaderText="Barcode"ControlStyle-CssClass="dvDataField"/><custom:BoundTextBoxFieldCssClass="dvDataField"DataField="box_description"HeaderText="Description"TextMode="MultiLine"Rows="5"Columns="50"Wrap="True"/><asp:TemplateFieldHeaderText="Box Category"><ItemTemplate><asp:Labelid="lblScheduleType"runat="server"Text='<%# Container.DataItem("schedule_record_type")%>'/></ItemTemplate><EditItemTemplate><asp:DropDownListrunat="server"id="ddlScheduleType"DataSourceID="dsScheduleType"SkinID=ddlBackColor="Pink"DataTextField="schedule_record_type"DataValueField="schedule_id"AutoPostBack=trueOnSelectedIndexChanged="ddlScheduleType_SelectedIndexChanged"SelectedValue='<%# Bind("box_schedule_type")%>'/></EditItemTemplate></asp:TemplateField>

<asp:TemplateFieldHeaderText="Status"><ItemTemplate><asp:Labelid="lblStatus"runat="server"Text='<%# Container.DataItem("status_name")%>'/></ItemTemplate><EditItemTemplate><asp:DropDownListrunat="server"id="ddlStatus"DataSourceID="dsStatus"SkinID=ddlBackColor="Pink"DataTextField="status_name"DataValueField="status_id"SelectedValue='<%# Bind("box_status")%>'/></EditItemTemplate></asp:TemplateField>

<asp:TemplateFieldHeaderText="Site"><ItemTemplate><asp:Labelid="lblSiteName"runat="server"Text='<%# Container.DataItem("site_name")%>'/></ItemTemplate><EditItemTemplate><asp:DropDownListrunat="server"id="ddlSite"DataSourceID="dsSite"BackColor="Pink"SkinID=ddlDataTextField="site_name"DataValueField="site_id"SelectedValue='<%# Bind("box_site")%>'/></EditItemTemplate></asp:TemplateField>

<asp:TemplateFieldHeaderText="Box Location"><ItemTemplate><asp:Labelid="lblLocation"runat="server"Text='<%# Container.DataItem("box_location")%>'/></ItemTemplate><EditItemTemplate><asp:DropDownListrunat="server"id="ddlBoxLocation"DataSourceID="SQLDSLocation"BackColor="Pink"SkinID=ddlDataTextField="location_id"DataValueField="location_id"SelectedValue='<%# Bind("box_location")%>'/></EditItemTemplate></asp:TemplateField>

<asp:TemplateFieldHeaderText="Cardholder Data"><ItemTemplate><asp:Labelid="lblCardholder"runat="server"Text='<%# Container.DataItem("box_cardholder_desc")%>'/></ItemTemplate><EditItemTemplate><asp:DropDownListrunat="server"id="ddlCardholder"BackColor="Pink"SkinID=ddlDataTextField="box_cardholder_desc"DataValueField="box_cardholder"SelectedValue='<%# Bind("box_cardholder")%>'><asp:ListItemSelected="True"Value=""Text=""/><asp:ListItemValue="Y"Text="Yes"/><asp:ListItemValue="N"Text="No"/></asp:DropDownList>

</EditItemTemplate></asp:TemplateField>

<asp:TemplateFieldHeaderText="Dept"><ItemTemplate><asp:Labelid="lblDept"runat="server"Text='<%# Container.DataItem("dept_name")%>'/></ItemTemplate><EditItemTemplate><asp:DropDownListrunat="server"id="ddlDept"DataSourceID="SQLdsDepartment"BackColor="Pink"SkinID=ddlDataTextField="dept_name"DataValueField="dept_id"SelectedValue='<%# Bind("fiserv_dept")%>'/></EditItemTemplate></asp:TemplateField>

<asp:BoundFieldDataField="date_start"HeaderText="Start Date"ControlStyle-CssClass="dvDataField"/>

<asp:TemplateFieldHeaderText="End Date"><ItemTemplate><asp:Labelid="lblDateEnd"runat="server"Text='<%# Container.DataItem("date_end")%>'/></ItemTemplate><EditItemTemplate><asp:TextBoxID="tbDateEnd"SkinID=tbrunat="server"Text='<%# Bind("date_end")%>'/></EditItemTemplate></asp:TemplateField>

<asp:TemplateFieldHeaderText="Destroy Month"><ItemTemplate><asp:Labelid="lblDestroyMonth"runat="server"Text='<%# Container.DataItem("date_dest_month")%>'/></ItemTemplate><EditItemTemplate><asp:TextBoxID="tbDestroyMonth"SkinID=tbrunat="server"ReadOnly=trueText='<%# Bind("date_dest_month")%>'/></EditItemTemplate></asp:TemplateField>

<asp:TemplateFieldHeaderText="Destroy Year"><ItemTemplate><asp:Labelid="lblDestroyYear"runat="server"Text='<%# Container.DataItem("date_dest_year")%>'/></ItemTemplate><EditItemTemplate><asp:TextBoxID="tbDestroyYear"SkinID=tbrunat="server"ReadOnly=trueText='<%# Bind("date_dest_year")%>'/></EditItemTemplate></asp:TemplateField>

<asp:CommandFieldShowEditButton="True"/></Fields></asp:DetailsView><Triggers><atlas:ControlEventTriggerControlID="ddlScheduleType"EventName="SelectedIndexChanged"/></Triggers></contentTemplate>

</ajax:UpdatePanel>

</td></tr></table><asp:SqlDataSourceID="SqlDsMaster"runat="server"SelectCommand="select dr_id, box_barcode, box_description, box_location, status_name, box_site, site_name from view_dr_master where box_site not in(97,98)"ConnectionString="<%$ ConnectionStrings:RetentionConnectionString%>"></asp:SqlDataSource><asp:SqlDataSourceID="SqlDsDetail"runat="server"ConnectionString="<%$ ConnectionStrings:RetentionConnectionString%>"SelectCommand="SELECT dr_id, box_barcode, box_schedule_type, box_description, box_location, box_status, status_name, box_site, site_name, fiserv_dept, dept_name,

date_start, date_end, date_dest_month, date_dest_year, box_cardholder, box_cardholder_desc

FROM view_dr_master WHERE (dr_id = @dotnet.itags.org.dr_id)">

<SelectParameters><asp:ControlParameterControlID="gvDrMaster"Name="dr_id"PropertyName="SelectedValue"Type="String"/></SelectParameters></asp:SqlDataSource>

<asp:SQLDataSourceID="dsScheduleType"Runat="Server"SelectCommand="SELECT schedule_id, schedule_record_type from dr_schedule GROUP BY schedule_id, schedule_record_type Union Select 0 schedule_id, 'Please select a box category' schedule_record_type From dr_schedule ORDER BY schedule_record_type"DataSourceMode="DataSet"ConnectionString="<%$ ConnectionStrings:RetentionConnectionString%>"></asp:SQLDataSource><asp:SQLDataSourceID="dsStatus"Runat="Server"SelectCommand="SELECT status_id, status_name from dr_status Union Select '' status_id, 'Please select a box status.' status_name from dr_status ORDER BY status_id "DataSourceMode="DataSet"ConnectionString="<%$ ConnectionStrings:RetentionConnectionString%>"/><asp:SQLDataSourceID="dsSite"Runat="Server"SelectCommand="select site_id, site_name from dr_site order by site_id"DataSourceMode="DataSet"ConnectionString="<%$ ConnectionStrings:RetentionConnectionString%>"/><asp:SQLDataSourceID="SQLDSLocation"Runat="Server"DataSourceMode="DataSet"ConnectionString="<%$ ConnectionStrings:RetentionConnectionString%>"></asp:SQLDataSource>

<asp:SQLDataSourceID="SQLdsDepartment"Runat="Server"SelectCommand="select dept_id, dept_name from dr_departments"DataSourceMode="DataSet"ConnectionString="<%$ ConnectionStrings:RetentionConnectionString%>"/>

</

asp:Content>Dim dtDestroyDateAs DateTime = dtDestroyDate.AddDays(nDistroyDays)

ctrlTbDY.Text = dtDestroyDate.Year

ctrlTbDM.Text = dtDestroyDate.Month

EndSub

Never mind figured it out, removed

<Triggers><atlas:ControlEventTriggerControlID="ddlScheduleType"EventName="SelectedIndexChanged"/></Triggers>

Detailed error messages with AJAX?

I'm building the front and back ends of a website and my issue is that when an error occurs in a section that is "ajaxed", the error is displayed in a javascript pop-up.

Is there any way that I can have it at least display a line number of the file causing the error? It's driving me crazy to debug, especially when I have dozens of classes working together. Please help. Thanks!

Ryan

Hi Ryan,

There are some good articles out there on the error handling in AJAX, but probably the first thing you need to do is to use the OnAsyncPostBackError attribute of the ScriptManager tag to add an event handler - allowing you to log the exception, or do something else with it.

Then you can start looking at supressing the alert, etc.

ScottGU's blog has a post which might be a good starting point when you want to go into a bit more depth, and produce a response which is more aimed at the users than developers!


You canadd custom handling of async errors pretty easily.

In that example, check out args._error for more details. _error.lineNumber and _error.stack might be helpful to you.