Hello,
I'm using vs2005 and ajax exentions 1.0.61025.0.
I have a page with a Gridview control that's inside of an update panel. I
also have a DetailsView on this page inside of another update panel. The
Detailsview handles the inserting of records into the Gridview.
The page is behaving as expected except the ItemInserting event (and there
the inserting) is being called twice. I have logic in place that is handling
this but it would be nice if the inserting events were not being called
twice and I don't see why this is happening. I'm including the html and the
code behind in case it could help. I'm sure this is simple but I just am not
getting it.
Thanks in advance
S
HTML:
<asp:ScriptMana ger ID="ScriptManag er1" runat="server">
</asp:ScriptManag er>
<asp:UpdatePane l ID="UpdatePanel 1" runat="server">
<ContentTemplat e>
<asp:GridView ID="gvStormDeta il" runat="server"
AutoGenerateCol umns="False" DataSourceID="d sStormDetail"
EnableViewState ="False" SkinID="gridvie wSkin" Width="568px">
<Columns>
<asp:BoundFie ld DataField="Stor mValueID"
HeaderText="Sto rmValueID" InsertVisible=" False"
ReadOnly="True" SortExpression= "StormValue ID"
Visible="False" />
<asp:BoundFie ld DataField="Stor mAssetType"
HeaderText="Ass et Category" SortExpression= "StormAssetType " >
<ItemStyle HorizontalAlign ="Center" />
</asp:BoundField>
<asp:BoundFie ld DataField="Stor mAssetTypeID"
HeaderText="Sto rmAssetTypeID" SortExpression= "StormAssetType ID"
Visible="False" />
<asp:BoundFie ld DataField="Stor mAssetName"
HeaderText="Sto rm Asset Name" SortExpression= "StormAssetName " >
<ItemStyle HorizontalAlign ="Center" />
</asp:BoundField>
<asp:BoundFie ld DataField="Uniq ueID"
HeaderText="Uni queID" SortExpression= "UniqueID" >
<ItemStyle HorizontalAlign ="Center" />
</asp:BoundField>
<asp:BoundFie ld DataField="Desc ription"
HeaderText="Des cription" SortExpression= "Descriptio n" >
<ItemStyle HorizontalAlign ="Center" />
</asp:BoundField>
<asp:BoundFie ld DataField="EstV alue"
HeaderText="Est imated Value" SortExpression= "EstValue"
DataFormatStrin g="{0:C0}" HtmlEncode="Fal se" >
<ItemStyle HorizontalAlign ="Right" />
</asp:BoundField>
<asp:BoundFie ld DataField="Cnty AssetID"
HeaderText="Cnt yAssetID" SortExpression= "CntyAssetI D"
Visible="False" />
</Columns>
</asp:GridView>
<br />
<asp:ObjectData Source ID="dsStormDeta il" runat="server"
OldValuesParame terFormatString ="original_{ 0}"
SelectMethod="G etStormAssetsBy CntyAssetdId"
TypeName="Storm AssetsMainBLL" EnableViewState ="False">
<SelectParamete rs>
<asp:SessionPar ameter Name="id"
SessionField="c ntyAssetId" Type="Int32" />
</SelectParameter s>
</asp:ObjectDataS ource>
<br />
</ContentTemplate >
<Triggers>
<asp:AsyncPostB ackTrigger ControlID="dvSt ormInsert"
EventName="Item Inserted" />
</Triggers>
</asp:UpdatePanel >
<asp:UpdatePane l ID="upInsert" runat="server" EnableViewState ="False"
UpdateMode="Con ditional" ChildrenAsTrigg ers="False">
<ContentTemplat e>
<asp:Label ID="lblAssetTyp e" runat="server"
EnableViewState ="False" Font-Size="10pt"
Text="Category" Width="88px" BackColor="#EFE FEF"
Height="18px"></asp:Label><asp: DropDownList ID="ddlAssetTyp e" runat="server"
AutoPostBack="T rue" DataSourceID="d sAssetTypes"
DataTextField=" StormAssetType"
DataValueField= "StormAssetType ID"
Width="156px"
EnableViewState ="False">
</asp:DropDownLis t><asp:ObjectDa taSource
ID="dsAssetType s" runat="server"
OldValuesParame terFormatString ="original_{ 0}"
SelectMethod="G etAssetTypesPlu sNone"
TypeName="Storm AssetTypeBLL" EnableViewState ="False"></asp:ObjectDataS ource>
<br />
<asp:DetailsVie w ID="dvStormInse rt"
runat="server"
DefaultMode="In sert"
EnableViewState ="False"
Height="50px"
Width="280px"
SkinID="details viewSkin"
AutoGenerateRow s="False"
DataKeyNames="S tormValueID"
DataSourceID="d sStormInsert"
OnItemInserted= "dvStormInsert_ ItemInserted"
OnItemInserting ="dvStormInsert _ItemInserting" >
<Fields>
<asp:BoundFie ld DataField="Stor mValueID"
HeaderText="Sto rmValueID" InsertVisible=" False"
ReadOnly="True" SortExpression= "StormValue ID" />
<asp:TemplateFi eld HeaderText="Cnt yAssetID"
SortExpression= "CntyAssetI D">
<EditItemTempla te>
<asp:TextBox ID="TextBox1" runat="server"
Text='<%# Bind("CntyAsset ID") %>'></asp:TextBox>
</EditItemTemplat e>
<InsertItemTemp late>
<asp:TextBox ID="txtCntyAsse tId" runat="server"
Enabled="False" EnableViewState ="False"
Text='<%# Bind("CntyAsset ID")
%>'></asp:TextBox>
</InsertItemTempl ate>
<ItemTemplate >
<asp:Label ID="Label1" runat="server" Text='<%#
Bind("CntyAsset ID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateFie ld>
<asp:TemplateFi eld HeaderText="Sto rm Asset"
SortExpression= "StormAsset ID">
<EditItemTempla te>
<asp:TextBox ID="TextBox2" runat="server"
Text='<%# Bind("StormAsse tID") %>'></asp:TextBox>
</EditItemTemplat e>
<InsertItemTemp late>
<asp:DropDownLi st ID="ddlStormAss et"
runat="server"
DataSourceID="d sStormAsset"
DataTextField=" StormAssetName"
DataValueField= "StormAsset ID"
Width="156px">
</asp:DropDownLis t>
<asp:ObjectData Source ID="dsStormAsse t"
runat="server"
OldValuesParame terFormatString ="original_{ 0}"
SelectMethod="G etStormAssetsBy AssetTypeId"
TypeName="Storm AssetsBLL">
<SelectParamete rs>
<asp:ControlPar ameter
ControlID="ddlA ssetType" Name="id" PropertyName="S electedValue"
Type="Int32" />
</SelectParameter s>
</asp:ObjectDataS ource>
</InsertItemTempl ate>
<ItemTemplate >
<asp:Label ID="Label2" runat="server" Text='<%#
Bind("StormAsse tID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateFie ld>
<asp:TemplateFi eld HeaderText="Des cription"
SortExpression= "Descriptio n">
<EditItemTempla te>
<asp:TextBox ID="TextBox4" runat="server"
Text='<%# Bind("Descripti on") %>'></asp:TextBox>
</EditItemTemplat e>
<InsertItemTemp late>
<asp:TextBox ID="txtDescript ion" runat="server"
Text='<%# Bind("Descripti on") %>'></asp:TextBox>
</InsertItemTempl ate>
<ItemTemplate >
<asp:Label ID="Label4" runat="server" Text='<%#
Bind("Descripti on") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateFie ld>
<asp:TemplateFi eld HeaderText="Uni queID"
SortExpression= "UniqueID">
<EditItemTempla te>
<asp:TextBox ID="TextBox5" runat="server"
Text='<%# Bind("UniqueID" ) %>'></asp:TextBox>
</EditItemTemplat e>
<InsertItemTemp late>
<asp:TextBox ID="txtUniqueId " runat="server"
Text='<%# Bind("UniqueID" ) %>'></asp:TextBox>
<asp:RequiredFi eldValidator ID="rfvUniqueId "
runat="server" EnableViewState ="False"
ErrorMessage="U niqueID is a required field"
ControlToValida te="txtUniqueId ">*</asp:RequiredFie ldValidator>
</InsertItemTempl ate>
<ItemTemplate >
<asp:Label ID="Label5" runat="server" Text='<%#
Bind("UniqueID" ) %>'></asp:Label>
</ItemTemplate>
</asp:TemplateFie ld>
<asp:TemplateFi eld ShowHeader="Fal se">
<InsertItemTemp late>
<asp:LinkButt on ID="lbInsert" runat="server"
CausesValidatio n="True" CommandName="In sert"
Text="Insert"></asp:LinkButton>
<asp:LinkButt on ID="lbCancel" runat="server"
CausesValidatio n="False" CommandName="Ca ncel"
OnClick="lbCanc el_Click"
Text="Cancel"></asp:LinkButton>
</InsertItemTempl ate>
<ItemTemplate >
<asp:LinkButt on ID="LinkButton1 " runat="server"
CausesValidatio n="False" CommandName="Ne w"
Text="New"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateFie ld>
</Fields>
</asp:DetailsView >
<asp:ObjectData Source ID="dsStormInse rt" runat="server"
EnableViewState ="False" InsertMethod="S tormValueInsert "
OldValuesParame terFormatString ="original_{ 0}" SelectMethod="G etStormValues"
TypeName="Storm ValueBLL">
<InsertParamete rs>
<asp:Paramete r Name="cntyAsset Id" Type="Int32" />
<asp:Paramete r Name="stormAsse tId" Type="Int32" />
<asp:Paramete r Name="descripti on" Type="String" />
<asp:Paramete r Name="uniqueId" Type="Int32" />
</InsertParameter s>
</asp:ObjectDataS ource>
</ContentTemplate >
<Triggers>
<asp:AsyncPostB ackTrigger ControlID="ddlA ssetType"
EventName="Sele ctedIndexChange d" />
</Triggers>
</asp:UpdatePanel >
Code Behind:
#Region "Constants"
Protected Const ASSETTYPEID As String = "assetTypeI d"
Protected Const CNTYASSETID_ROW As Integer = 0
'Protected Const ASSETTYPE_ROW As Integer = 1
Protected Const STORMASSET_ROW As Integer = 1
Protected Const DESCRIPTION_ROW As Integer = 2
Protected Const UNIQUEID_ROW As Integer = 3
Protected Const ASSETTYPE_DD As String = "ddlAssetTy pe"
Protected Const STORMASSET_DD As String = "ddlStormAs set"
Protected Const CNTYASSETID_TXT As String = "txtCntyAssetId "
Protected Const DESCRIPTION_TXT As String = "txtDescription "
Protected Const UNIQUE_TXT As String = "txtUniqueI d"
#End Region
Protected Sub dvStormInsert_I temInserting(By Val sender As Object, ByVal e
As System.Web.UI.W ebControls.Deta ilsViewInsertEv entArgs) Handles
dvStormInsert.I temInserting
e.Cancel = True
Dim ddl As DropDownList =
dvStormInsert.R ows(STORMASSET_ ROW).FindContro l(STORMASSET_DD )
If Not ddl Is Nothing Then
If ddl.SelectedVal ue = "" Then Return
Dim sBLL As New StormValueBLL
Dim stormAssetId, uid As Integer
Dim desc As String
stormAssetId = ddl.SelectedVal ue
uid = e.Values(UNIQUE ID_ROW - 1)
desc = e.Values(DESCRI PTION_ROW - 1)
sBLL.StormValue Insert(e.Values (CNTYASSETID_RO W), stormAssetId,
desc, uid)
ResetDropdowns( )
Dim txt As TextBox =
dvStormInsert.R ows(DESCRIPTION _ROW).FindContr ol(DESCRIPTION_ TXT)
If Not txt Is Nothing Then txt.Text = Nothing
txt = dvStormInsert.R ows(UNIQUEID_RO W).FindControl( UNIQUE_TXT)
If Not txt Is Nothing Then txt.Text = Nothing
upInsert.DataBi nd()
End If
End Sub
Protected Sub Page_LoadComple te(ByVal sender As Object, ByVal e As
System.EventArg s) Handles Me.LoadComplete
SetCntyAssetId( )
End Sub
Protected Sub dvStormInsert_I temInserted(ByV al sender As Object, ByVal e
As System.Web.UI.W ebControls.Deta ilsViewInserted EventArgs) Handles
dvStormInsert.I temInserted
SetCntyAssetId( )
ResetDropdowns( )
End Sub
Protected Sub SetCntyAssetId( )
Dim txt As TextBox =
dvStormInsert.R ows(CNTYASSETID _ROW).FindContr ol(CNTYASSETID_ TXT)
If Not txt Is Nothing Then
Dim id As Integer = Session("cntyAs setId")
If id 0 Then
txt.Text = id
End If
End If
End Sub
Protected Sub ResetDropdowns( )
ddlAssetType.Se lectedValue = -1
End Sub
Protected Sub lbCancel_Click( ByVal sender As Object, ByVal e As
System.EventArg s)
Me.ddlAssetType .SelectedValue = -1
Me.upInsert.Dat aBind()
'Dim ddl As DropDownList =
dvStormInsert.R ows(STORMASSET_ ROW).FindContro l(STORMASSET_DD )
'If Not ddl Is Nothing Then
' ddl.Items.Clear ()
'End If
End Sub