views:

248

answers:

2

Hi, I have problem with my UserControl. It has inside the UpdatePanel, but it must be placed inside the tag to get worked (otherwise, the PostBack is not asynchronous)

The problem is, if I put that UserControl in e.g. Default.aspx page, the error appears "A page can have only one server-side Form tag"

how to cope with that ?

[edit]

the UserControl.ascx code:

 <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="PodmiotyZwolnioneCtrl.ascx.cs" Inherits="FormularzPodatkowy.PodmiotyZwolnioneCtrl" %>
 <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajax" %>

<link href="AjaxStyle.css" rel="stylesheet" type="text/css" />

<!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" >

<body>
<form id="form1" runat="server">
<div>
        <asp:UpdatePanel ID="UpdatePanel1" 
                         UpdateMode="Conditional"
                         runat="server">
            <ContentTemplate>
               <fieldset>
               <legend>UpdatePanel content</legend>
                <!-- Other content in the panel. -->
                <%=DateTime.Now.ToString() %>
                <br />
                <asp:Button ID="Button1" 
                            Text="Refresh Panel" 
                            runat="server" />
                </fieldset>
            </ContentTemplate>
        </asp:UpdatePanel>
    </div>
</form>
</body>
</html>

the WebForm1.aspx code:

 <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="FormularzPodatkowy.WebForm1" %>

 <%@ Register src="PodmiotyZwolnioneCtrl.ascx" tagname="PodmiotyZwolnioneCtrl" tagprefix="uc1" %>

 <!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>
</head>
<body>
<form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server" />
    <uc1:PodmiotyZwolnioneCtrl ID="PodmiotyZwolnioneCtrl1" runat="server" />
</form>
 </body>
</html>
A: 

You should check both the usercontrol and the page and make sure that you only have one <form id='form1' runat='server'> tag in your markup. Having more than one will give you the error that you're experiencing.

Good luck, and hope this helps some.

Chris
I know, but if there will be only 1 form the UpdatePanel won't "work"
Tony
+4  A: 

Your code should be:

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="PodmiotyZwolnioneCtrl.ascx.cs" Inherits="FormularzPodatkowy.PodmiotyZwolnioneCtrl" %>
 <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajax" %>

<link href="AjaxStyle.css" rel="stylesheet" type="text/css" />

<div>
        <asp:UpdatePanel ID="UpdatePanel1" 
                         UpdateMode="Conditional"
                         runat="server">
            <ContentTemplate>
               <fieldset>
               <legend>UpdatePanel content</legend>
                <!-- Other content in the panel. -->
                <%=DateTime.Now.ToString() %>
                <br />
                <asp:Button ID="Button1" 
                            Text="Refresh Panel" 
                            runat="server" />
                </fieldset>
            </ContentTemplate>
        </asp:UpdatePanel>
    </div>

It looks like you converted a page to a control and forgot to remove the page-specific elements

Also, if your postbacks are not asynchronous, look at your web.config for:

 <xhtmlConformance mode="Legacy"/>

and change it to:

 <xhtmlConformance mode="Transitional"/>

I just spent three days at work finding that solution to UpdatePanel always posting back to the server.

Jim Schubert
+1 beat me to it. :-)
jchapa
I resolved the problem, I've used Your code, and then I've moved the asp:ScriptManager from the .ascx file to my Default.aspx page. That worked ! :)P.S. I'll check Your web.config solution, it sounds usefulThanks for Your help !
Tony