Link to home
Create AccountLog in
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

Avatar of CB_Thirumalai
CB_Thirumalai
Flag of India image

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.
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.
Avatar of bobstery
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.
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.
Could you post the master page and content page code here so I can have a look and analyse the difference?
ASKER CERTIFIED SOLUTION
Avatar of CB_Thirumalai
CB_Thirumalai
Flag of India image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
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.