AJAX question (I think)

S

SAL

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:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:GridView ID="gvStormDetail" runat="server"
AutoGenerateColumns="False" DataSourceID="dsStormDetail"
EnableViewState="False" SkinID="gridviewSkin" Width="568px">
<Columns>
<asp:BoundField DataField="StormValueID"
HeaderText="StormValueID" InsertVisible="False"
ReadOnly="True" SortExpression="StormValueID"
Visible="False" />
<asp:BoundField DataField="StormAssetType"
HeaderText="Asset Category" SortExpression="StormAssetType" >
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="StormAssetTypeID"
HeaderText="StormAssetTypeID" SortExpression="StormAssetTypeID"
Visible="False" />
<asp:BoundField DataField="StormAssetName"
HeaderText="Storm Asset Name" SortExpression="StormAssetName" >
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="UniqueID"
HeaderText="UniqueID" SortExpression="UniqueID" >
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="Description"
HeaderText="Description" SortExpression="Description" >
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="EstValue"
HeaderText="Estimated Value" SortExpression="EstValue"
DataFormatString="{0:C0}" HtmlEncode="False" >
<ItemStyle HorizontalAlign="Right" />
</asp:BoundField>
<asp:BoundField DataField="CntyAssetID"
HeaderText="CntyAssetID" SortExpression="CntyAssetID"
Visible="False" />
</Columns>
</asp:GridView>
<br />
<asp:ObjectDataSource ID="dsStormDetail" runat="server"
OldValuesParameterFormatString="original_{0}"
SelectMethod="GetStormAssetsByCntyAssetdId"
TypeName="StormAssetsMainBLL" EnableViewState="False">
<SelectParameters>
<asp:SessionParameter Name="id"
SessionField="cntyAssetId" Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>
<br />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="dvStormInsert"
EventName="ItemInserted" />
</Triggers>
</asp:UpdatePanel>
<asp:UpdatePanel ID="upInsert" runat="server" EnableViewState="False"
UpdateMode="Conditional" ChildrenAsTriggers="False">
<ContentTemplate>
<asp:Label ID="lblAssetType" runat="server"
EnableViewState="False" Font-Size="10pt"
Text="Category" Width="88px" BackColor="#EFEFEF"
Height="18px"></asp:Label><asp:DropDownList ID="ddlAssetType" runat="server"
AutoPostBack="True" DataSourceID="dsAssetTypes"
DataTextField="StormAssetType"
DataValueField="StormAssetTypeID"
Width="156px"
EnableViewState="False">
</asp:DropDownList><asp:ObjectDataSource
ID="dsAssetTypes" runat="server"
OldValuesParameterFormatString="original_{0}"
SelectMethod="GetAssetTypesPlusNone"
TypeName="StormAssetTypeBLL" EnableViewState="False"></asp:ObjectDataSource>
<br />
<asp:DetailsView ID="dvStormInsert"
runat="server"
DefaultMode="Insert"
EnableViewState="False"
Height="50px"
Width="280px"
SkinID="detailsviewSkin"
AutoGenerateRows="False"
DataKeyNames="StormValueID"
DataSourceID="dsStormInsert"
OnItemInserted="dvStormInsert_ItemInserted"
OnItemInserting="dvStormInsert_ItemInserting" >
<Fields>
<asp:BoundField DataField="StormValueID"
HeaderText="StormValueID" InsertVisible="False"
ReadOnly="True" SortExpression="StormValueID" />
<asp:TemplateField HeaderText="CntyAssetID"
SortExpression="CntyAssetID">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server"
Text='<%# Bind("CntyAssetID") %>'></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="txtCntyAssetId" runat="server"
Enabled="False" EnableViewState="False"
Text='<%# Bind("CntyAssetID")
%>'></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%#
Bind("CntyAssetID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Storm Asset"
SortExpression="StormAssetID">
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server"
Text='<%# Bind("StormAssetID") %>'></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:DropDownList ID="ddlStormAsset"
runat="server"
DataSourceID="dsStormAsset"
DataTextField="StormAssetName"
DataValueField="StormAssetID"
Width="156px">
</asp:DropDownList>
<asp:ObjectDataSource ID="dsStormAsset"
runat="server"
OldValuesParameterFormatString="original_{0}"
SelectMethod="GetStormAssetsByAssetTypeId"
TypeName="StormAssetsBLL">
<SelectParameters>
<asp:ControlParameter
ControlID="ddlAssetType" Name="id" PropertyName="SelectedValue"
Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%#
Bind("StormAssetID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Description"
SortExpression="Description">
<EditItemTemplate>
<asp:TextBox ID="TextBox4" runat="server"
Text='<%# Bind("Description") %>'></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="txtDescription" runat="server"
Text='<%# Bind("Description") %>'></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%#
Bind("Description") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="UniqueID"
SortExpression="UniqueID">
<EditItemTemplate>
<asp:TextBox ID="TextBox5" runat="server"
Text='<%# Bind("UniqueID") %>'></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="txtUniqueId" runat="server"
Text='<%# Bind("UniqueID") %>'></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvUniqueId"
runat="server" EnableViewState="False"
ErrorMessage="UniqueID is a required field"
ControlToValidate="txtUniqueId">*</asp:RequiredFieldValidator>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label5" runat="server" Text='<%#
Bind("UniqueID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ShowHeader="False">
<InsertItemTemplate>
<asp:LinkButton ID="lbInsert" runat="server"
CausesValidation="True" CommandName="Insert"
Text="Insert"></asp:LinkButton>
<asp:LinkButton ID="lbCancel" runat="server"
CausesValidation="False" CommandName="Cancel"
OnClick="lbCancel_Click"
Text="Cancel"></asp:LinkButton>
</InsertItemTemplate>
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server"
CausesValidation="False" CommandName="New"
Text="New"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Fields>
</asp:DetailsView>
<asp:ObjectDataSource ID="dsStormInsert" runat="server"
EnableViewState="False" InsertMethod="StormValueInsert"
OldValuesParameterFormatString="original_{0}" SelectMethod="GetStormValues"
TypeName="StormValueBLL">
<InsertParameters>
<asp:parameter Name="cntyAssetId" Type="Int32" />
<asp:parameter Name="stormAssetId" Type="Int32" />
<asp:parameter Name="description" Type="String" />
<asp:parameter Name="uniqueId" Type="Int32" />
</InsertParameters>
</asp:ObjectDataSource>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ddlAssetType"
EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>


Code Behind:
#Region "Constants"
Protected Const ASSETTYPEID As String = "assetTypeId"
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 = "ddlAssetType"
Protected Const STORMASSET_DD As String = "ddlStormAsset"
Protected Const CNTYASSETID_TXT As String = "txtCntyAssetId"
Protected Const DESCRIPTION_TXT As String = "txtDescription"
Protected Const UNIQUE_TXT As String = "txtUniqueId"
#End Region

Protected Sub dvStormInsert_ItemInserting(ByVal sender As Object, ByVal e
As System.Web.UI.WebControls.DetailsViewInsertEventArgs) Handles
dvStormInsert.ItemInserting
e.Cancel = True
Dim ddl As DropDownList =
dvStormInsert.Rows(STORMASSET_ROW).FindControl(STORMASSET_DD)

If Not ddl Is Nothing Then
If ddl.SelectedValue = "" Then Return
Dim sBLL As New StormValueBLL
Dim stormAssetId, uid As Integer
Dim desc As String
stormAssetId = ddl.SelectedValue
uid = e.Values(UNIQUEID_ROW - 1)
desc = e.Values(DESCRIPTION_ROW - 1)
sBLL.StormValueInsert(e.Values(CNTYASSETID_ROW), stormAssetId,
desc, uid)
ResetDropdowns()
Dim txt As TextBox =
dvStormInsert.Rows(DESCRIPTION_ROW).FindControl(DESCRIPTION_TXT)
If Not txt Is Nothing Then txt.Text = Nothing
txt = dvStormInsert.Rows(UNIQUEID_ROW).FindControl(UNIQUE_TXT)
If Not txt Is Nothing Then txt.Text = Nothing
upInsert.DataBind()
End If
End Sub

Protected Sub Page_LoadComplete(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.LoadComplete
SetCntyAssetId()
End Sub

Protected Sub dvStormInsert_ItemInserted(ByVal sender As Object, ByVal e
As System.Web.UI.WebControls.DetailsViewInsertedEventArgs) Handles
dvStormInsert.ItemInserted
SetCntyAssetId()
ResetDropdowns()
End Sub

Protected Sub SetCntyAssetId()
Dim txt As TextBox =
dvStormInsert.Rows(CNTYASSETID_ROW).FindControl(CNTYASSETID_TXT)
If Not txt Is Nothing Then
Dim id As Integer = Session("cntyAssetId")
If id > 0 Then
txt.Text = id
End If
End If
End Sub

Protected Sub ResetDropdowns()
ddlAssetType.SelectedValue = -1
End Sub

Protected Sub lbCancel_Click(ByVal sender As Object, ByVal e As
System.EventArgs)
Me.ddlAssetType.SelectedValue = -1
Me.upInsert.DataBind()
'Dim ddl As DropDownList =
dvStormInsert.Rows(STORMASSET_ROW).FindControl(STORMASSET_DD)
'If Not ddl Is Nothing Then
' ddl.Items.Clear()
'End If
End Sub
 
A

Allen Chen [MSFT]

Hi,

Since you're using VB.NET, both specifying:

OnItemInserting="dvStormInsert_ItemInserting"

in aspx and specifying:

Handles dvStormInsert.ItemInserting

in aspx.vb will attach the event handler to the ItemInserting event.
Therefore, the event handler will be called twice.

To solve this problem you can remove either of above ones.

Please let me know if it works.

Regards,
Allen Chen
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

Note: MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 2 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions. Issues of this
nature are best handled working with a dedicated Microsoft Support Engineer
by contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
S

SAL

Ahh, yes. that did work. I don't know how that happened as I don't recall
adding it in both places.

I have another issue with this web page involving AJAX, I believe.

I have a button on this page. The Click even does not fire. However, when
the button is clicked, the text for a required field validator in the
details view appears.????

Should I repost for this question?

S
 
A

Allen Chen [MSFT]

Hi,

Glad to know you've solved this issue.

As to the new one, since it's a different issue I think it's better to
start a new post for it. Please post some code that can reproduce this
problem and I'll follow up.

Regards,
Allen Chen
Microsoft Online Community Support
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,527
Members
44,999
Latest member
MakersCBDGummiesReview

Latest Threads

Top