468,115 Members | 2,078 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,115 developers. It's quick & easy.

AJAX question (I think)

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.DetailsViewInsertEventAr gs) Handles
dvStormInsert.ItemInserting
e.Cancel = True
Dim ddl As DropDownList =
dvStormInsert.Rows(STORMASSET_ROW).FindControl(STO RMASSET_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(DE SCRIPTION_TXT)
If Not txt Is Nothing Then txt.Text = Nothing
txt = dvStormInsert.Rows(UNIQUEID_ROW).FindControl(UNIQU E_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.DetailsViewInsertedEvent Args) Handles
dvStormInsert.ItemInserted
SetCntyAssetId()
ResetDropdowns()
End Sub

Protected Sub SetCntyAssetId()
Dim txt As TextBox =
dvStormInsert.Rows(CNTYASSETID_ROW).FindControl(CN TYASSETID_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(STO RMASSET_DD)
'If Not ddl Is Nothing Then
' ddl.Items.Clear()
'End If
End Sub
Nov 19 '08 #1
3 1342
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:
ms****@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subs...#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/subs.../aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 20 '08 #2
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

"Allen Chen [MSFT]" <v-******@online.microsoft.comwrote in message
news:EA**************@TK2MSFTNGHUB02.phx.gbl...
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:
ms****@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subs...#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/subs.../aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no
rights.

Nov 20 '08 #3
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

Nov 21 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

11 posts views Thread by Yarco | last post: by
4 posts views Thread by bobzimuta | last post: by
8 posts views Thread by needin4mation | last post: by
8 posts views Thread by darrel | last post: by
7 posts views Thread by Thirsty Traveler | last post: by
31 posts views Thread by Tony | last post: by
9 posts views Thread by Trapulo | last post: by
4 posts views Thread by Peter | last post: by
1 post views Thread by Mark B | last post: by
7 posts views Thread by =?Utf-8?B?QmlsbHkgWmhhbmc=?= | last post: by
5 posts views Thread by didacticone | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.