Avatar of bobstery
bobstery
 asked on

AutoPostBack not working with Master page for SelectedIndexChanged

I have several web pages that use a master page (see code below).  The problem that I am having is the fact that when my pages use the master page the AutoPostBack isnt working e.g. I have a drop down list with which I have activated the SelectedIndexChanged event, which populates a gridView.  This doesnt work when I use the master page but does when I dont.

Does auto postback work with Master Pages or is there something I need to do in order to get it working with them?

******* MASTER PAGE *********
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="test.master.cs" Inherits="test" %>
 
<!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>
    <title>Test - Master Page</title>
    <link rel="stylesheet" type="text/css" href="styles.css" />
</head>
<body>    
    <div id="container">
        <div id="header">
            <h1>Test</h1>
        </div>        
                    
            <asp:contentplaceholder id="mainBody" runat="server" />        
        
            <div id="footer">
                <p>Test</p>
            </div>        
    </div>        
</body>
</html>
 
********* Example of Page using MASTER PAGE ****************
<%@ Page Language="C#" MasterPageFile="~/test.master" AutoEventWireup="true" CodeFile="testSizes.aspx.cs" Inherits="testSizes" EnableEventValidation="true" %>
 
<form id="form1" runat="server">
<asp:Content ID="Content1" ContentPlaceHolderID="mainBody" runat="Server">       
&.
<asp:DropDownList ID="testItemDDL" runat="server" DataSourceID="testItemsDS"
                                    DataTextField="clti_name" DataValueField="clti_id" OnDataBound="testItemDDL_DataBound" AutoPostBack="True" OnSelectedIndexChanged="testItemDDL_SelectedIndexChanged">
                                </asp:DropDownList>

Open in new window

ASP.NET

Avatar of undefined
Last Comment
CB_Thirumalai

8/22/2022 - Mon
CB_Thirumalai

Refer these links
http://forums.asp.net/p/1012839/1355754.aspx#1355754
http://www.webdeveloper.com/forum/archive/index.php/t-51694.html

I see   ---  <form id="form1" runat="server"> --- in content page.  I think this is not allowed.  Remove this and try.
CB_Thirumalai

I also see that you do not have a form tag in the master page.  You need to have a <form tag in the master page.
bobstery

ASKER
I have tried placing the form tag in the master page and the content page both do not work.  It only works if I don't use a master page for some reason.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
CB_Thirumalai

May be you have something different in the master and content pages.  I have tried and was able to handle the post back and make the selected index changed event fire.  I am not sure how you have it in your forms.
bobstery

ASKER
Could you post the master page and content page code here so I can have a look and analyse the difference?
ASKER CERTIFIED SOLUTION
CB_Thirumalai

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
CB_Thirumalai

Forgot to mention the difference.  The only difference is, the dropdown you have is bound to a DataSourceID, whereas I have dummy data in it using ListItems.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.