Solved

Update Gridview with an UpdatePanel - Can 28 Different Triggers Call The Same VB.NET Subroutine?

Posted on 2009-07-13
3
537 Views
Last Modified: 2012-08-13
I have a Gridview with 28 linkbuttons which control the filtering of the gridview thru their OnClick events.

I'm trying to use the linkbuttons as Triggers for an Update Panel, and I started with the A linkbutton. In order to get the Gridview to update (and prevent a server error), I had explicitly define a lnkA_Click subroutine (because you have to specify a standard linkbutton event in the Trigger declaration). How can I avoid having to define a lnkB_Click, lnkC_Click etc subroutines for each trigger?

Before trying to convert I had a single subroutine which was associated with the OnClick events with all the linkbuttons, but I wasn't able to use it with the trigger. Any way to get all the triggers to call the same subroutine or do I have to explicitly define one for each trigger :(

I don't mind having to make 28 triggers, I just want to avoid blowing up my code file with 28 subroutines.

Thanks for any ideas!
<tr>

                    <td colspan="2">

                        <br />

                        <asp:Panel ID="pnlFilter" runat="server" CssClass="TextLabel" OnClick="LetterChanged">

                                <asp:LinkButton ID="lnk0" runat="server" Text="[0-9]" ></asp:LinkButton>&nbsp;

                                <asp:LinkButton ID="lnkA" runat="server" Text="A" AutoPostBack="True"></asp:LinkButton>&nbsp;                                                                                                                   

                                <asp:LinkButton ID="lnkB" runat="server" Text="B" AutoPostBack="True"></asp:LinkButton>&nbsp;                                                                                                                   

                                <asp:LinkButton ID="lnkC" runat="server" Text="C" AutoPostBack="True"></asp:LinkButton>&nbsp;                                                                                                                   

                                <asp:LinkButton ID="lnkD" runat="server" Text="D" AutoPostBack="True"></asp:LinkButton>&nbsp;                                                                                                                   

                                <asp:LinkButton ID="lnkE" runat="server" Text="E" AutoPostBack="True"></asp:LinkButton>&nbsp;                                                                                                                   

                                <asp:LinkButton ID="lnkF" runat="server" Text="F" AutoPostBack="True"></asp:LinkButton>&nbsp;                                                                                                                   

                                <asp:LinkButton ID="lnkG" runat="server" Text="G" AutoPostBack="True"></asp:LinkButton>&nbsp;                                                                                                                   

                                <asp:LinkButton ID="lnkH" runat="server" Text="H" AutoPostBack="True"></asp:LinkButton>&nbsp;                                                                                                                   

                                <asp:LinkButton ID="lnkI" runat="server" Text="I" AutoPostBack="True"></asp:LinkButton>&nbsp;                                                                                                                   

                                <asp:LinkButton ID="lnkJ" runat="server" Text="J" AutoPostBack="True"></asp:LinkButton>&nbsp;                                                                                                                   

                                <asp:LinkButton ID="lnkK" runat="server" Text="K" AutoPostBack="True"></asp:LinkButton>&nbsp;                                                                                                                   

                                <asp:LinkButton ID="lnkL" runat="server" Text="L" AutoPostBack="True"></asp:LinkButton>&nbsp;                                                                                                                   

                                <asp:LinkButton ID="lnkM" runat="server" Text="M" AutoPostBack="True"></asp:LinkButton>&nbsp;                                                                                                                   

                                <asp:LinkButton ID="lnkN" runat="server" Text="N" AutoPostBack="True"></asp:LinkButton>&nbsp;                                                                                                                   

                                <asp:LinkButton ID="lnkO" runat="server" Text="O" AutoPostBack="True"></asp:LinkButton>&nbsp;                                                                                                                   

                                <asp:LinkButton ID="lnkP" runat="server" Text="P" AutoPostBack="True"></asp:LinkButton>&nbsp;                                                                                                                   

                                <asp:LinkButton ID="lnkQ" runat="server" Text="Q" AutoPostBack="True"></asp:LinkButton>&nbsp;                                                                                                                   

                                <asp:LinkButton ID="lnkR" runat="server" Text="R" AutoPostBack="True"></asp:LinkButton>&nbsp;                                                                                                                   

                                <asp:LinkButton ID="lnkS" runat="server" Text="S" AutoPostBack="True"></asp:LinkButton>&nbsp;                                                                                                                   

                                <asp:LinkButton ID="lnkT" runat="server" Text="T" AutoPostBack="True"></asp:LinkButton>&nbsp;                                                                                                                   

                                <asp:LinkButton ID="lnkU" runat="server" Text="U" AutoPostBack="True"></asp:LinkButton>&nbsp;                                                                                                                   

                                <asp:LinkButton ID="lnkV" runat="server" Text="V" AutoPostBack="True"></asp:LinkButton>&nbsp;                                                                                                                   

                                <asp:LinkButton ID="lnkW" runat="server" Text="W" AutoPostBack="True"></asp:LinkButton>&nbsp;                                                                                                                   

                                <asp:LinkButton ID="lnkX" runat="server" Text="X" AutoPostBack="True"></asp:LinkButton>&nbsp;

                                <asp:LinkButton ID="lnkY" runat="server" Text="Y" AutoPostBack="True"></asp:LinkButton>&nbsp;

                                <asp:LinkButton ID="lnkZ" runat="server" Text="Z" AutoPostBack="True"></asp:LinkButton>&nbsp;

                                <asp:LinkButton ID="lnkAll" runat="server" Text="ALL" AutoPostBack="True"></asp:LinkButton>

                        </asp:Panel>

                      <asp:UpdatePanel ID="updList" runat="server">

                        <ContentTemplate>

                        <asp:Panel ID="pnlProdList" runat="server" Height="300px" Width="800px" ScrollBars="both">

                            <asp:HiddenField ID="hdnLetter" runat="server" />

                            <asp:GridView ID="gvProd" runat="server" BackColor="#EEEEEE" GridLines="horizontal" AllowSorting="false" CssClass="TextLabel" Width="780px"

                                AutoGenerateColumns="false" DataKeyNames="key" EnableViewState="false" >

                                <SelectedRowStyle BackColor="LightYellow" Font-Bold="true" />

                                <HeaderStyle BackColor="LightSlateGray" ForeColor="White" />

                                <AlternatingRowStyle BackColor="#DDDDDD" Font-Bold="false" />

                                <RowStyle Font-Bold="false" />                                

                                <Columns>                                                                        

                                    <asp:CommandField SelectText="Details." ShowSelectButton="true" />

                                    <asp:BoundField DataField="prodname" HeaderText="Name" SortExpression="prod" />

                                </Columns>                                                        

                            </asp:GridView>

                        </asp:Panel>

                       </ContentTemplate>

                        <Triggers>

                          <asp:AsyncPostBackTrigger ControlID="lnkA" EventName="Click"></asp:AsyncPostBackTrigger>

				  <asp:AsyncPostBackTrigger ControlID="lnkB" EventName="Click"></asp:AsyncPostBackTrigger>                        

			        <!-- Will include a trigger for each letter I guess :( -->

				</Triggers>

                    </asp:UpdatePanel>

                    </td>

                </tr>
 
 
 

    'PROBLEM - DON'T WANT TO HAVE TO MAKE 27 OF THESE FUNCTIONS, 1 FOR EACH LETTER/OPTION

    Protected Sub lnkA_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkA.Click

        'SEt the hidden filter letter value based on the clicked letter & rebind datasource

        If CType(sender, LinkButton).Text = "ALL" Then

            hdnLetter.Value = "%"

        Else

            hdnLetter.Value = CType(sender, LinkButton).Text

        End If

	

	  'This function below pulls filtered list data and rebinds the gridview

        GetProdListData(sender, e) 
 

    End Sub

Open in new window

0
Comment
Question by:synapse88
  • 2
3 Comments
 
LVL 13

Expert Comment

by:crazyman
ID: 24840160
Just call your Routine HandleLinkClick or something more generic, and you can specify the same handler for all you link buttons and then
handle the differnces in their.

Remove the Handles lnkA.Click and put it in your markup for each one, like :


<asp:LinkButton ID="lnkA" runat="server" Text="A" OnClick="HandleClickLink" AutoPostBack="True"></asp:LinkButton>
0
 
LVL 15

Accepted Solution

by:
jinal earned 500 total points
ID: 24840166
Hello ,

See first line of attached code.

You can avoid that by adding lnkC.Click , lnkD.Click

Protected Sub lnkA_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkA.Click, lnkB.Click , lnkC.Click , lnkD.Click

Try  and tell.

Protected Sub lnkA_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkA.Click, lnkB.Click , lnkC.Click

        'SEt the hidden filter letter value based on the clicked letter & rebind datasource

        If CType(sender, LinkButton).Text = "ALL" Then

            hdnLetter.Value = "%"

        Else

            hdnLetter.Value = CType(sender, LinkButton).Text

        End If
 

        'This function below pulls filtered list data and rebinds the gridview

        GetProdListData(sender, e)
 

    End Sub

Open in new window

0
 
LVL 13

Expert Comment

by:crazyman
ID: 24852176
Why would you want to avoid the more elegant solution, having 28 handles at the end is hardly a good approach.
Why not just add it through the markup, much easier to maintain and much tidier.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Error in JQuery 5 39
Extracting last characters in a substring 5 21
Variable Event ? 3 23
VB 2005 Tooltips on Form Load Event 15 16
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Introduction HyperText Transfer Protocol (http://www.ietf.org/rfc/rfc2616.txt) or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now