views:

4053

answers:

2

hi, i have a master page with following scriptmanager tag:

<asp:ScriptManager ID="scriptManger" EnablePartialRendering="true" runat="server" >
 <Scripts>
  <asp:ScriptReference Path="~/common/js/jquery-1.3.2.js" />
  <asp:ScriptReference Path="~/common/js/validation.js" />
 </Scripts>
</asp:ScriptManager>

My aspx page is :

    <%@ Page Language="C#" AutoEventWireup="true" MasterPageFile="~/common/MasterPages/Login.master" CodeBehind="SecurityQuestionsEnroll.aspx.cs" Inherits="Login.SecurityQuestionsEnroll" %>

    <%@ Register src="~/controls/Views/Login/SecurityQuestions.ascx" tagname="SecurityQuestions" tagprefix="uc1" %>

and this is the user control:

  <asp:UpdatePanel ID="UpdatePanel1" runat="server" ChildrenAsTriggers="true" UpdateMode="always"  >
<ContentTemplate>  
    <asp:DataList ID="dlSecurityQuestions" runat="server" AutoPostBack="true" OnSelectedIndexChanged ="dlSecurityQuestions_SelectedIndexChanged">
        <ItemTemplate>
            <div>
                <asp:Label ID="lbl_question" AssociatedControlID="lst_question" runat="server"><%# DataBinder.Eval(Container.DataItem, "QuestionName")%></asp:Label>
                <asp:DropDownList ID="lst_question" runat="server" AutoPostBack="true" >
                    <asp:ListItem Value="0">Select a Question...</asp:ListItem>
                    <asp:ListItem Value="1">Select a Question1..</asp:ListItem>
                </asp:DropDownList>
            </div>
            <div>
                <asp:Label ID="lbl_answer1" AssociatedControlID="txt_answer" runat="server">Answer *</asp:Label>
                <asp:TextBox ID="txt_answer" runat="server" />
                <div id="validate"></div>
            </div>
        </ItemTemplate>
    </asp:DataList>
</ContentTemplate>
</asp:UpdatePanel>

I have tried most of the options which google recommends, but i am not able to do a partial postback. evry time selectedindex is changed it does a full page postback. the drop down as you can see is in a itemtemplate and is repeated. what do you think I am doing wrong that its not firing postback of just the update panel.

A: 

I built a little test project that mimics your files a little bit. I'm not using a DataList and I've moved the area that needs to be updated into a seperate div (meaning that if you keep the DataList, I don't think your question/answer would be located inside the DataList the way you have it now. So right now, the sample I built just grabs the text from a drop down list and updates a literal in the UpdatePanel with the option the user selected.

Here's my code:

MasterPage:

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site1.master.cs" Inherits="UpdatePanelTest.Site1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title></title>
    <asp:ContentPlaceHolder ID="head" runat="server">
    </asp:ContentPlaceHolder>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="scriptManger" EnablePartialRendering="true" runat="server" >
        <Scripts>
            <asp:ScriptReference Path="~/common/js/jquery-1.3.2.min.js" />
        </Scripts>
    </asp:ScriptManager>

    <div>
        <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">

        </asp:ContentPlaceHolder>
    </div>


    </form>
</body>
</html>

Default page (no additional code in code-behind):

<%@ Page Title="" Language="C#" MasterPageFile="~/Site1.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="UpdatePanelTest.Default" %>
<%@ Register src="Selector.ascx" tagname="Selector" tagprefix="uc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

    <uc1:Selector ID="Selector1" runat="server" />

</asp:Content>

User Control (Html):

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Selector.ascx.cs" Inherits="UpdatePanelTest.Selector" %>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" ChildrenAsTriggers="true" UpdateMode="always"  >
<ContentTemplate>  
    <asp:DropDownList ID="lst_question" runat="server" AutoPostBack="true" 
    onselectedindexchanged="lst_question_SelectedIndexChanged" >
        <asp:ListItem Value="0">Option 1</asp:ListItem>
        <asp:ListItem Value="1">Option 2</asp:ListItem>
    </asp:DropDownList>

    <div>
        <asp:Literal ID="Literal1" runat="server"></asp:Literal>
    </div>
</ContentTemplate>
</asp:UpdatePanel>

User Control (Code-behind):

using System;
using System.Web.UI.WebControls;

namespace UpdatePanelTest
{
    public partial class Selector : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void lst_question_SelectedIndexChanged(object sender, EventArgs e)
        {
            var ddl = sender as DropDownList;
            Literal1.Text = "You selected " + ddl.SelectedItem.Text;
        }
    }
}
mannish
THANKS but the whole issue is with the datalist, items in the datalist are not able to trigger the update panel postback
Can you clarify a bit more about what you're trying to accomplish with the data list by using it in that manner (e.g. what you expect to have happen within the data list)? I'll play around with it a bit more, but since I don't have access to your project, I'm only guessing at what is happening behind the scenes in your code behind file. I would be helpful to see your OnSelectedIndexChanged handler at the very least.
mannish
The items in the list duplicate according to a NumberOfQuestion int property. So if number of question is 2, 2 itemtemplate will show, if 4 ...then 4 ...and so on.Different pages use this control, but have different number of dropdown lists displayed at a time.
A: 

I see <asp:UpdatePanel ID="id" runat="server" ChildrenAsTriggers="true" UpdateMode="always" > in your UpdatePanel definition - this needs to be UpdateMode="Conditional" if you want your UpdatePanel to work asynchronously. No idea why the ASP:NET devs didn't set it to Conditional as a default in the first place (I still sometimes forget it).

Maybe that's already it?

Oliver