By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,939 Members | 1,600 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,939 IT Pros & Developers. It's quick & easy.

ASP.NET question about datagrid row changes

P: n/a
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.
Nov 19 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Use a javascript function call delay and then from javascript call the click
event

"lanem" wrote:
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.

Nov 19 '05 #2

P: n/a
Thanks. How do you call the click event from JavaScript?

"Sérgio" wrote:
Use a javascript function call delay and then from javascript call the click
event

"lanem" wrote:
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.

Nov 19 '05 #3

P: n/a
window.document.getElementById("buttonName").click ();

"lanem" wrote:
Thanks. How do you call the click event from JavaScript?

"Sérgio" wrote:
Use a javascript function call delay and then from javascript call the click
event

"lanem" wrote:
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.

Nov 19 '05 #4

P: n/a
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.

"Sérgio" wrote:
Use a javascript function call delay and then from javascript call the click
event

"lanem" wrote:
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.

Nov 19 '05 #5

P: n/a
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
"lanem" <la***@discussions.microsoft.com> wrote in message
news:E6**********************************@microsof t.com...
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.

"Srgio" wrote:
Use a javascript function call delay and then from javascript call the
click
event

"lanem" wrote:
> 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.

Nov 19 '05 #6

P: n/a
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

"Darrin J. Olson" wrote:
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
"lanem" <la***@discussions.microsoft.com> wrote in message
news:E6**********************************@microsof t.com...
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.

"Sérgio" wrote:
Use a javascript function call delay and then from javascript call the
click
event

"lanem" wrote:

> 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.


Nov 19 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.