ASP.NET question about datagrid row changes

G

Guest

I have a page that shows some data in a datagrid. All rows are updateable
and then the changes are saved by hitting the "Save Changes" button. It is
not a row by row save. All edits are made and then all altered rows are
saved at once. It can be big, so I only want to save the ones that have
changed. I'm keeping track of the changed rows in ViewState with this code:

Protected Sub RowChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs)
Dim intRowIndex As Integer

colRowsChanged = ViewState("RowsChanged")

intRowIndex = dgPhoneNumbers.DataKeys(CType(CType(sender,
Control).NamingContainer, DataGridItem).ItemIndex)

If Not colRowsChanged.Contains(intRowIndex) Then
colRowsChanged.Add(intRowIndex)
End If

ViewState("RowsChanged") = colRowsChanged
End Sub

This Sub is called from each textbox's OnTextChanged event like this:

<asp:TextBox ID="txtDisplayName" Text='<%#
Container.DataItem("DisplayName")%>' Columns="20" MaxLength="40"
OnTextChanged="RowChanged" AutoPostBack="True" runat="server" />

It all works fine, except that the RowChanged sub only fires when the row
change is followed by a tab or specifically clicking away from the textbox.
This causes a problem if someone changes a few rows and directly clicks "Save
Changes" without purposefully clicking away from the textbox first. Most
users are going to just click "Save Changes" after making the last change, so
this is causing problems.

Is there another way to fire this Sub? Or other suggestions.
Thanks.
 
G

Guest

I have been looking into trying the time delay, but I don't really see how
that is going to help. When the person clicks the "Save Changes" button
after changing that last row, the RowChanged function fires and the click
event doesn't fire, b/c the page has posted back for the RowChanged function.
Then, the user has to hit "Save Changes" again. A time delay on the client
side will not matter once the page has posted back.
Thanks.
 
D

Darrin J. Olson

I think your best bet would be to fire a client side event prior to the
post-back when clicking on the "Save Changes" button.

On your server-side button, in the code-behind you could add an "onClick"
attribute to the button, so that when it's clicked it will run the specified
javascript function prior to posting. In the script you can set focus
somewhere else, or take the item out of "edit mode".

Hope that helps.

-Darrin
 
G

Guest

I use two buttons , the first is visible and is html button that call client
side function, and the second is a server button that is hidden and is call
in the client side function with the delay function. when the postback is
call the focus the was in the text field have change to the html button and
the event onrowchange is fired.

I hope that helps

Sérgio
 

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

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,069
Latest member
SimplyleanKetoReviews

Latest Threads

Top