Quantcast
Channel: Web Forms
Viewing all articles
Browse latest Browse all 23244

convert postback to code behind

$
0
0

I am pulling data into a gridview. The code below will show two different buttons depending on the data.
If a user clicks on either button it opens up another page that does an insert into a SQL table.
My question is can I accomplish the same action without posting to another page?
How can I do this in vb.net code behind of the same page?

My users are complaining that there are to many clicks with the current page. So if I can do the insert without the user getting another page popping up they would be much happier.

I'm just not able to see how to do this.

.aspx code

<asp:GridView ID="GV" runat="server" width="100%" Style="position: static" AllowPaging="True" AllowSorting="True"
                                            AlternatingRowStyle-CssClass="gridAltRow" AutoGenerateColumns="False"
                                            CssClass="grid" EnableModelValidation="True" PageSize="40"
                                            RowStyle-CssClass="gridRow"><PagerStyle CssClass="pgr" /><PagerSettings Position="TopAndBottom" /><RowStyle Wrap="true" /><Columns><asp:TemplateField HeaderText="Hold" ShowHeader="True"><ItemTemplate><asp:Button ID="BtnHold" runat="server" CausesValidation="false"
                        CommandName="Hold" DataField="ExtensionAttribute3"
                        OnClientClick="window.document.forms[0].target='_blank';"
                        PostBackUrl='<%# "/.../.../TerminationsHold.aspx?per="+Eval("EA3") %>'
                        Text="No - Hold?" /><asp:Button ID="BtnRemove" runat="server" CausesValidation="false"
                        CommandName="Remove" OnClientClick="window.document.forms[0].target='_blank';"
                        PostBackUrl='<%# "/.../.../TerminationsRemove.aspx?per="+Eval("EA3") %>'
                        Text="Yes - Remove?" /></ItemTemplate></asp:TemplateField></Columns></asp:GridView>

vb.net code of the page that is doing the insert now....

 Try
            '// Update data from sql table
            cmd.CommandText = "Update Terminations SET Hold = 'True', HoldBy = '" & myMail & "', HoldDate = GETDATE() Where EA3='" & HFExt3.Value & "'"
            cmd.ExecuteNonQuery()
        Catch ex As Exception
            Root.Log.WriteToDBRequestError(Root.Actions.Update, ex)
        End Try





Viewing all articles
Browse latest Browse all 23244

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>