attipa
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-categorylis t-text" AutoPostBack="true" Width="110" Height="16" />
<asp:DropDownList ID="categorylist" runat="server" CssClass="body-categorylis
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
I checked that everything worked fine.
may be check you the Autopostback property again. And it may be modified in code to false
ASKER
i have tried everything and it doesn't work. here is my code.
usercontrol
<%@ Control Language="VB" AutoEventWireup="true" CodeFile="category-navigat ion.ascx.v b" Inherits="UserControls_cat egory_navi gation" %>
<asp:DropDownList ID="categorylist" runat="server" CssClass="body-categorylis t-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(connectionSt ring)
Try
connection.Open()
Dim command As SqlCommand = New SqlCommand("GetCategoriesW O7", connection)
command.CommandType = CommandType.StoredProcedur e
Dim adapter As SqlDataAdapter = New SqlDataAdapter(command)
adapter.Fill(CatDS, "Category")
categorylist.DataSource = CatDS
categorylist.DataTextField = "Name"
categorylist.DataValueFiel d = "CategoryID"
categorylist.DataBind()
categorylist.Items.Insert( 0, "Categories")
Catch e As Exception
Finally
connection.Close()
End Try
Return Nothing
End Function
Protected Sub categorylist_SelectedIndex Changed(By Val sender As Object, ByVal e As System.EventArgs) Handles categorylist.SelectedIndex Changed
If Not categorylist.SelectedIndex = 0 Then
Response.Redirect("http://www.xxx.com/new_xxa/" & TextForLinks(categorylist. SelectedIt em.ToStrin g()) & "/" & categorylist.SelectedValue & ".aspx")
End If
End Sub
master page
<%@ Page Language="VB" AutoEventWireup="true" CodeFile="about.aspx.vb" Inherits="about" %>
<%@ Register Src="UserControls/category -navigatio n.ascx" TagName="categorynavigatio n" 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="tru e"/> in configuration or <%@ Page EnableEventValidation="tru e" %> 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.Regist erForEvent Validation 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.
usercontrol
<%@ Control Language="VB" AutoEventWireup="true" CodeFile="category-navigat
<asp:DropDownList ID="categorylist" runat="server" CssClass="body-categorylis
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(connectionSt
Try
connection.Open()
Dim command As SqlCommand = New SqlCommand("GetCategoriesW
command.CommandType = CommandType.StoredProcedur
Dim adapter As SqlDataAdapter = New SqlDataAdapter(command)
adapter.Fill(CatDS, "Category")
categorylist.DataSource = CatDS
categorylist.DataTextField
categorylist.DataValueFiel
categorylist.DataBind()
categorylist.Items.Insert(
Catch e As Exception
Finally
connection.Close()
End Try
Return Nothing
End Function
Protected Sub categorylist_SelectedIndex
If Not categorylist.SelectedIndex
Response.Redirect("http://www.xxx.com/new_xxa/" & TextForLinks(categorylist.
End If
End Sub
master page
<%@ Page Language="VB" AutoEventWireup="true" CodeFile="about.aspx.vb" Inherits="about" %>
<%@ Register Src="UserControls/category
<!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="tru
i even put enableEventValidation=true
someone please help me, i am in a huge rush to finish this project.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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....
ASKER
yes i do
<%@ 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.maste
Inherits="MasterPages_Defa
<%@ 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?