Link to home
Start Free TrialLog in
Avatar of attipa
attipaFlag for United States of America

asked on

autopostback does not fire when used in a usercontrol

i have a dropdownlist which has the autopostback=true.  i can't get it to fire because it is in a usercontrol which goes on a master page.  how can i get this to work?

<asp:DropDownList ID="categorylist" runat="server" CssClass="body-categorylist-text" AutoPostBack="true" Width="110" Height="16" />
Avatar of NauticalNonsense
NauticalNonsense
Flag of United States of America image

I just tried this on a test page... control is:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="Test.ascx.cs" Inherits="Controls_Test" %>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True">
    <asp:ListItem Value="1">1</asp:ListItem>
    <asp:ListItem Value="2">2</asp:ListItem>
    <asp:ListItem Value="3">3</asp:ListItem>
</asp:DropDownList>
Master Page is:
<%@  Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs"
    Inherits="MasterPages_Default_MasterPage" %>
<%@ Register TagPrefix="site" TagName="test" Src="~/Controls/Test.ascx" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
</head>
<body marginwidth="0" marginheight="0" topmargin="0" leftmargin="0" vlink="#000066"
    link="#000066">
    <form id="form1" runat="server">
        <site:test runat="server" ID="aaa" />
        <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
        </asp:ContentPlaceHolder>
    </form>
</body>
</html>

1.) are you sure it's NOT posting back? locally, it might be too quick
2.) you have the user control call inside your <form> tag?
3.) are you programmatically registering/loading this control?

btw, on my test, it worked fine doing the postback.
hi,
 I checked that everything worked fine.

may be check you the Autopostback property again. And it may be modified in code to false
Avatar of attipa

ASKER

i have tried everything and it doesn't work.  here is my code.

usercontrol
<%@ Control Language="VB" AutoEventWireup="true" CodeFile="category-navigation.ascx.vb" Inherits="UserControls_category_navigation" %>
        <asp:DropDownList ID="categorylist" runat="server" CssClass="body-categorylist-text" AutoPostBack="true" Width="110" Height="16" />

usercontrol codebehind
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        getcats()
    End Sub
Public Function getcats()

        Dim connection As New SqlConnection(connectionString)

        Try
            connection.Open()
            Dim command As SqlCommand = New SqlCommand("GetCategoriesWO7", connection)
            command.CommandType = CommandType.StoredProcedure
            Dim adapter As SqlDataAdapter = New SqlDataAdapter(command)
            adapter.Fill(CatDS, "Category")

            categorylist.DataSource = CatDS
            categorylist.DataTextField = "Name"
            categorylist.DataValueField = "CategoryID"
            categorylist.DataBind()

            categorylist.Items.Insert(0, "Categories")

        Catch e As Exception

        Finally
            connection.Close()
        End Try

        Return Nothing
    End Function
    Protected Sub categorylist_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles categorylist.SelectedIndexChanged
        If Not categorylist.SelectedIndex = 0 Then
           Response.Redirect("http://www.xxx.com/new_xxa/" & TextForLinks(categorylist.SelectedItem.ToString()) & "/" & categorylist.SelectedValue & ".aspx")
        End If
    End Sub


master page
<%@ Page Language="VB" AutoEventWireup="true" CodeFile="about.aspx.vb" Inherits="about" %>
<%@ Register Src="UserControls/category-navigation.ascx" TagName="categorynavigation" TagPrefix="uc3" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
</head>
<body class="default-body">
<uc3:categorynavigation ID="Categorynavigation1" runat="server" />
</body>
</html>


i even got this error message a few times:
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 even put enableEventValidation=true in my web.config....still no luck.

someone please help me, i am in a huge rush to finish this project.
ASKER CERTIFIED SOLUTION
Avatar of NauticalNonsense
NauticalNonsense
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of attipa

ASKER

setting the EnableEventValidation=True in the Page Directive did it!  thanks.
Happy to be of service :)
By the way, for the record, do you NOT have a <FORM tag on your master page? I was thinking that it would be the form tag, ... however....
Avatar of attipa

ASKER

yes i do