Why isn't the ItemCommand event handler getting fired in my asp:Repeater embedded in a User Control in Asp.Net (VB.Net) application?

Hi:

I have a small ASP.Net application based which wraps a asp:DataGrid and an asp:Repeater in a user control.
The idea is to create a user control which has a "tabbed grid."
It is based on this sample from MSDN:
https://msdn.microsoft.com/en-us/magazine/cc164104.aspx

I have downloaded the C# version and it works as advertised.

For the purposes of the client's requirements, we are attempting to rewrite the control in VB.Net.
The tab in this example is wrapped in an asp:Repeater control.
We have run into an issue where the OnItemCommand handler (on the server side) does not get fired.
Clicking on the button (tab) does however generate a postback.

I've tried adding an OnClick event for the (tab) buttons dynamically when the repeater's ItemBoundData event.
That call event does not get triggered either.

Here is the basic HTML of the pages/user controls:

Test Page:
<%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/Site.master"
    CodeBehind="test3m.aspx.vb" Inherits="TestTabbedGridView.test3m" EnableEventValidation="false" %>

<%@ Register Src="~/UserControls/DataSetGrid.ascx" TagName="DataSetGrid" TagPrefix="ucDataSetGrid" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <ucDataSetGrid:DataSetGrid runat="server" width="600px" height="310px" ID="dataGrid" />
</asp:Content>

Open in new window

DataSetGrid User Control:
<%@ Control Language="vb" CodeBehind="DataSetGrid.ascx.vb"
    Inherits="TestTabbedGridView.DataSetGrid" %>
<%@ Register Src="~/UserControls/TabStrip.ascx" TagName="TabStrip" TagPrefix="ucTabStrip" %>
<table id="__theTable" runat="server" bgcolor="ivory" border="1" cellpadding="0"
    cellspacing="0">
    <tr>
        <td valign="top">
            <ucTabStrip:TabStrip ID="ts" runat="server" SelectedBackColor="Cyan" OnSelectionChanged="SelectionChanged" />
            <asp:DataGrid ID="__theGrid" runat="server" AllowPaging="true" CellPadding="2" CellSpacing="0"
                Font-Name="verdana" Font-Size="8pt" GridLines="none" OnItemCommand="ItemCommand"
                OnPageIndexChanged="PageIndexChanged" OnSelectedIndexChanged="SelectedIndexChanged"
                PageSize="12" Width="100%">
                <PagerStyle font-name="webdings" Font-Size="150%" NextPageText="4" Position="top"
                    PrevPageText="3" />
                <SelectedItemStyle BackColor="yellow" />
                <AlternatingItemStyle BackColor="ivory" />
                <ItemStyle BackColor="#eeeeee" />
            </asp:DataGrid>
        </td>
    </tr>
</table>

Open in new window

TabStrip User Control:
<%@ Control Language="vb" CodeBehind="TabStrip.ascx.vb" Inherits="TestTabbedGridView.TabStrip" %>
<div class="lightbluebackground">
    <asp:Repeater ID="rpt" runat="server" OnItemCommand="ItemCommandFired">
        <HeaderTemplate>
            <table cellpadding="0" cellspacing="0" border="0">
                <tr>
        </HeaderTemplate>
        <ItemTemplate>
            <td>
                <asp:Button CausesValidation="false" runat="server" ID="btnTab" Text="<%# Container.DataItem %>"
                    CommandName="CmdSelectTab"
                    BorderWidth="1px" BorderStyle="solid" />
            </td>
        </ItemTemplate>
    </asp:Repeater>
</div>

Open in new window


Are there differences between Asp.Net C# and VB.Net which I need to be aware of?
Is this somehow involve the ViewState?

Can someone help get me pointed in the right direction or provide clues to help track why those events are not getting fired?

Thanks,
JohnB
LVL 1
jxbmaSoftware ConsultantAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SriVaddadiCommented:
Tabstrip user control does not seem to be well formed html.
The table element is not properly formed as i note from the above html. Try removing the table, tr, td and give it a shot. If that works then you know where the problem is.
0
jxbmaSoftware ConsultantAuthor Commented:
SriVaddadi::>>

I removed references to the table, tr, td from the repeater templates.

My updated Tabstrip user control looks like this now:
<%@ Control Language="vb" CodeBehind="TabStrip.ascx.vb" Inherits="TestTabbedGridView.TabStrip" %>
<div class="lightbluebackground">
    <asp:Repeater ID="rpt" runat="server" OnItemCommand="ItemCommandFired">
        <HeaderTemplate>
        </HeaderTemplate>
        <ItemTemplate>
                <asp:Button CausesValidation="false" runat="server" ID="btnTab" Text="<%# Container.DataItem %>"
                    CommandName="CmdSelectTab"
                    BorderWidth="1px" BorderStyle="solid" />
        </ItemTemplate>
        <FooterTemplate>
        </FooterTemplate>
    </asp:Repeater>
</div>

Open in new window

When I click on a button in the tab, I get the following error/exception in the browser:
Invalid postback or callback argument.  Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page.  For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them.  If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.
I tried setting the EnableEventValidation="false" in the page. When this is set to "false," the event fires correctly without throwing
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.ArgumentException: Invalid postback or callback argument.  Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page.  For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them.  If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace: 


[ArgumentException: Invalid postback or callback argument.  Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page.  For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them.  If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.]
   System.Web.UI.ClientScriptManager.ValidateEvent(String uniqueId, String argument) +144
   System.Web.UI.Control.ValidateEvent(String uniqueID, String eventArgument) +111
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +29
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +35
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1724

Open in new window


If I set EnableEventValidation="false" on my page, then the button event fires correctly in is handled on the server side.
Disabling EventValidation is not on option for our application.

I've googled around for a solution and tried several things.
1) If I remove the asp:repeater and just have a single button embedded on user control, it events fire fine without error.
2) I tried wrapping in an asp:UpdatePanel, but I couldn't seem to get that to work.

We would like to use this user control implementation if at all possible, as this control will be contained on several pages across several projects.

How do I identify what is causing the issue?
How do I best proceed?

Thanks,
JohnB
0
SriVaddadiCommented:
As i understand you are looking for cross-page post using the button click. if that is the case, then please use PostBackUrl property of the button.

Also, make sure you check the page's IsValid property.
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

jxbmaSoftware ConsultantAuthor Commented:
::>>SriVaddadi::>> Thanks for the response.
Can you please explain further?

So to be clear. I have an asp::repeater which is contained in a user control (ASCX) which is contained in a page (aspx). The repeater contains a button. When I click on the button, that's when the validation error gets thrown.

1) Does that really constitute as cross-page post? I've done post backs from other user controls (ASCX) with no issues. The difference here seems to be what ever the asp.net repeater control adds to the mix.

2) What is the pages IsValid property and when/where should I be checking/accessing it?
     On page load?

Thanks,
JB
0
SriVaddadiCommented:
JB,

Could you please post your ItemCommand event handler code snippet

As you did not set the PostBackUrl property of the button to the same page, it is being considered as a cross page and throwing the error.

Set the PostBackUrl property to the same page and that should solve the issue.

IsValid property of the page validates all the server controls and returns true\false depending on whether the server controls are valid or not.

You can read more on it here
0
jxbmaSoftware ConsultantAuthor Commented:
SriVaddadi::> So, if I embed a UserControl (ASCX) in a page, a postback originated from the user control is considered to be a cross page post back?

The ItemCommand handler on the ASCX does not get fired. The exception occurs before I get to the ItemCommand handler.
0
SriVaddadiCommented:
Not the user control. The button inside the repeater is causing the issue. It will cause the issue until u set the PostBackUrl property
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jxbmaSoftware ConsultantAuthor Commented:
SriVaddadi::> I'm a little confused.
So, button in the repeater control (which is contained in the user control) is causing the issue.
I set the postBackUrl to..., the page or the usercontrol (ASCX).
Do I actually have access to the underlying page at that point?

Thx,
JB
0
SriVaddadiCommented:
Could you please post the ItemCommand codes snippet
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.