ASP.NET Web Forms and Ajaxcontroltoolkit

Asked

Viewed 197 times

2

When adding a ajax:ModalPopupExtender on my page I’m having the following error

inserir a descrição da imagem aqui

    <%@ Page Title="" Language="C#" MasterPageFile="~/Admin/Admin.master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Devcompy.ClientWebForms.Admin.Default" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content runat="server" ContentPlaceHolderID="ScriptContent">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <asp:Button ID="Button1" runat="server" Text="Button" />
    <asp:Panel ID="Panel1" runat="server">Teste</asp:Panel>
    <ajax:ModalPopupExtender ID="ModalPopupExtender1" runat="server"
        TargetControlID="Button1"
        PopupControlID="Panel1"
        BackgroundCssClass="modalBackground">
    </ajax:ModalPopupExtender>
</asp:Content>

Admin.master.

<%@ Master Language="C#" MasterPageFile="~/Admin/AdminBase.Master" AutoEventWireup="true" CodeBehind="~/Admin/Admin.master.cs" Inherits="Devcompy.ClientWebForms.Admin.AdminMasterPage" %>

<%@ Register Src="MensagemUserControl.ascx" TagName="MensagemUserControl" TagPrefix="uc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
    <title>Devcompy40</title>
    <asp:ContentPlaceHolder ID="HeadContent" runat="server">
    </asp:ContentPlaceHolder>
</asp:Content>
<asp:Content ID="Content5" runat="server" ContentPlaceHolderID="ScriptContent">
    <asp:ContentPlaceHolder ID="ScriptContent" runat="server">
    </asp:ContentPlaceHolder>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="HeaderBodyContent" runat="server">
    <div class="title">
        <h1>Devcompy 40
        </h1>
    </div>
    <div class="loginDisplay">
        <asp:LoginView ID="HeadLoginView" runat="server" EnableViewState="false">
            <AnonymousTemplate>
                [ <a href="~/Admin/Login/LoginPage.aspx" id="HeadLoginStatus" runat="server">Entrar</a> ]
            </AnonymousTemplate>
            <LoggedInTemplate>
                Bem Vindo <span class="bold">
                    <asp:LoginName ID="HeadLoginName" runat="server" />
                </span>! [
                <asp:LoginStatus ID="HeadLoginStatus" runat="server" LogoutAction="Redirect" LogoutText="Sair" LogoutPageUrl="~/Admin/Default.aspx" />
                ]
            </LoggedInTemplate>
        </asp:LoginView>
    </div>
    <div class="clear hideSkiplink">
        <asp:LoginView ID="LoginView1" runat="server" EnableViewState="false">
            <AnonymousTemplate>
            </AnonymousTemplate>
            <LoggedInTemplate>
                <asp:UpdatePanel ID="MainMenuUpdatePanel" runat="server">
                    <ContentTemplate>
                    </ContentTemplate>
                </asp:UpdatePanel>
            </LoggedInTemplate>
        </asp:LoginView>
        <noscript>
            <div class="disabled" style="background-color: White; padding: 10px;">
                <img src='<%= ResolveUrl("~/Imagens/no.gif") %>' width="16" height="16" alt="javascript disabled" />
                O JavaScript está desabilitado no seu navegador. Quando habilitar seu JavaScript recarregue esta página que este aviso desaparecerá.
            </div>
        </noscript>
        <asp:Menu ID="NavigationMenu" runat="server" CssClass="menu" IncludeStyleBlock="False" ClientIDMode="Static" EnableViewState="true" Orientation="Horizontal"
            MaximumDynamicDisplayLevels="30">
            <DataBindings>
                <asp:MenuItemBinding DataMember="siteMapNode" NavigateUrlField="url" SelectableField="Selectable" TextField="title" />
            </DataBindings>
        </asp:Menu>
    </div>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="server">
    <div>
        <asp:SiteMapPath ID="SiteMapPath1" runat="server" SiteMapProvider="WebAdminSiteMap" EnableViewState="false" CurrentNodeStyle-ForeColor="Black" RenderCurrentNodeAsLink="True">
            <CurrentNodeStyle ForeColor="Blue" Font-Bold="True"></CurrentNodeStyle>
        </asp:SiteMapPath>
    </div>
    <div style="margin-bottom: 40px;">
        <div>
            <uc1:MensagemUserControl ID="MensagemUserControl1" runat="server" />
        </div>
        <div class="clear main">
            <div class="clear">
                <div id="loading">
                    <asp:ContentPlaceHolder ID="MainContent" runat="server" />
                </div>
                <div style="float: right;">
                    <asp:LinkButton ID="LinkButton1" runat="server" OnClientClick="window.print();" EnableViewState="false">Imprimir Página</asp:LinkButton>
                </div>
            </div>
            <div class="clear">
            </div>
        </div>
    </div>
</asp:Content>
<asp:Content ID="Content4" runat="server" ContentPlaceHolderID="FooterContent" EnableViewState="false">
    <span>
        <%= DateTime.Now.Year %>
        - Copyright todos direitos reservados para <a href="http://www.deltacompy.com.br">Grupo Deltacompy</a> - Informática - Santa Maria/RS</span>
</asp:Content>

Admin.Master.Cs

using System;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using Devcompy.Repositories.Web.Base;
using System.IO;
using Devcompy.Repositories.Business2.Seguranca;

namespace Devcompy.ClientWebForms.Admin
{
    public partial class AdminMasterPage : DevcompyMasterPage
    {
        protected override void PageLoad()
        {            
            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "RegistrarJquery", "RegistrarJquery();", true);
            ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "ConfirmDialog", " ConfirmDialog(this, ''); ", true);

            if (!Request.RawUrl.Contains("/Admin/Login/LoginPage.aspx"))
            {
                if (this.UsuarioId == 0)
                {
                    FormsAuthentication.SignOut();
                    FormsAuthentication.RedirectToLoginPage();
                }
            }

            if (!this.IsPostBack)
            {
                if ((!Request.RawUrl.Contains("/Admin/Seguranca/Usuario/UsuarioMudarSenhaPage.aspx")) &&
                    (Session["MudarSenha"] != null && Convert.ToBoolean(Session["MudarSenha"]) == true))
                {
                    this.Redirect("~/Admin/Seguranca/Usuario/UsuarioMudarSenhaPage.aspx");
                }

                SetSiteMapDataSource();
            }
        }

        private void SetSiteMapDataSource()
        {
            NavigationMenu.DataSource = GetDataSource();
            NavigationMenu.DataBind();
        }

        private XmlDataSource GetDataSource()
        {
            XmlDataSource oXmlDataSource = new XmlDataSource();
            oXmlDataSource.XPath = "siteMap/siteMapNode";
            string fileName = Server.MapPath("~/Admin/_SiteMap/" + this.Page.User.Identity.Name + ".sitemap");

            if (!File.Exists(fileName))
            {
                string path = Server.MapPath("~/Admin/_SiteMap/");
                new UsuarioBusiness2().GerarXmlSiteMap(path, UsuarioBusiness2.Create(this.UsuarioId));
            }

            oXmlDataSource.DataFile = fileName;

            oXmlDataSource.DataBind();

            return oXmlDataSource;
        }
    }
}

Adminbase.Master

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="AdminBase.master.cs" Inherits="Devcompy.ClientWebForms.Admin.AdminBase" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="pt-br">
<head id="Head1" runat="server">
    <meta name="robots" content="noindex, nofollow" />

    <title>Devcompy40</title>
    <link href="~/Styles/Admin/Site.css" rel="stylesheet" type="text/css" />
    <link href="~/Styles/Admin/Devcompy.css" rel="stylesheet" type="text/css" />

    <script src="<%= Page.ResolveUrl("~/Scripts/jquery-2.1.1.js") %>" type="text/javascript"></script>
    <script src="<%= Page.ResolveUrl("~/Scripts/autoNumeric-1.7.5.js") %>" type="text/javascript"></script>
    <script src="<%= Page.ResolveUrl("~/Scripts/jquery.maskedinput.js") %>" type="text/javascript"></script>

    <%--<script src="<%= Page.ResolveUrl("~/Scripts/jquery.cookies.2.2.0.min.js") %>" type="text/javascript"></script>

    <script src="<%= Page.ResolveUrl("~/Scripts/minified/jquery.ui.core.min.js") %>" type="text/javascript"></script>

    <script src="<%= Page.ResolveUrl("~/Scripts/jquery.ui.core.js") %>" type="text/javascript"></script>
    <script src="<%= Page.ResolveUrl("~/Scripts/jquery.ui.widget.js") %>" type="text/javascript"></script>
    <script src="<%= Page.ResolveUrl("~/Scripts/jquery.ui.position.js") %>" type="text/javascript"></script>
    <script src="<%= Page.ResolveUrl("~/Scripts/jquery.ui.menu.js") %>" type="text/javascript"></script>
    <script src="<%= Page.ResolveUrl("~/Scripts/jquery.ui.autocomplete.js") %>" type="text/javascript"></script>


    <script src="<%= Page.ResolveUrl("~/Scripts/minified/jquery.ui.widget.min.js") %>" type="text/javascript"></script>
    <script src="<%= Page.ResolveUrl("~/Scripts/minified/jquery.ui.button.min.js") %>" type="text/javascript"></script>
    <script src="<%= Page.ResolveUrl("~/Scripts/minified/jquery.ui.tabs.min.js") %>" type="text/javascript"></script>
    <script src="<%= Page.ResolveUrl("~/Scripts/minified/jquery.ui.datepicker.min.js") %>" type="text/javascript"></script>

        <script src="<%= Page.ResolveUrl("~/Scripts/jquery.ui.position.js") %>" type="text/javascript"></script>
    <script src="<%= Page.ResolveUrl("~/Scripts/jquery.ui.spinner.js") %>" type="text/javascript"></script>--%>

    <script src="<%= Page.ResolveUrl("~/Scripts/jquery-ui-1.10.4.js") %>" type="text/javascript"></script>
    <script src="<%= Page.ResolveUrl("~/Scripts/Devcompy.js") %>?<%= new Random().Next() %>" type="text/javascript"></script>

    <link href="<%= Page.ResolveUrl("~/Styles/themes/base/jquery.ui.all.css") %>" rel="stylesheet" type="text/css" />

    <asp:ContentPlaceHolder ID="HeadContent" runat="server">
    </asp:ContentPlaceHolder>
</head>
<body runat="server">
    <form id="form1" runat="server" clientidmode="Static">
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <asp:HiddenField ID="vsKey" runat="server" />
        <input type="hidden" id="hidLastTab" value="0" name="hidLastTab" />
        <div class="page">
            <div class="header">
                <asp:ContentPlaceHolder ID="HeaderBodyContent" runat="server" />
            </div>
            <div class="main">
                <asp:ContentPlaceHolder ID="MainContent" runat="server" />
            </div>
            <div class="footer">
                <asp:ContentPlaceHolder ID="FooterContent" runat="server" />
            </div>
        </div>
    </form>
    <asp:ContentPlaceHolder ID="ScriptContent" runat="server">
    </asp:ContentPlaceHolder>
</body>
</html>

Adminbase.Master.Cs

using System;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using Devcompy.Lib;
using Devcompy.Lib.Validations;
using Devcompy.Repositories.Web.Base;
using Devcompy.Models.Entities.Segurancas;
using Devcompy.Repositories.Business2.Seguranca;

namespace Devcompy.ClientWebForms.Admin
{
    public partial class AdminBase : DevcompyMasterPage
    {

        protected override void PageLoad()
        {
            if (!Request.RawUrl.Contains("/Admin/Login/LoginPage.aspx"))
            {
                if (this.UsuarioId == 0)
                {
                    FormsAuthentication.SignOut();
                    FormsAuthentication.RedirectToLoginPage();
                }
            }

            if (!this.IsPostBack)
                VerificarPermissoes();
        }

        private void VerificarPermissoes()
        {
            //DevcompyLib.IsLocalIpAddress();
            if (!this.IsPostBack && this.UsuarioId != 1)
            {
                if ((!Request.RawUrl.Contains("/Admin/Seguranca/Usuario/UsuarioMudarSenhaPage.aspx")) &&
                    (Session["MudarSenha"] != null && Devcompy2.ToBoolean(Session["MudarSenha"].ToString(), false) == true))
                {
                    this.Redirect("~/Admin/Seguranca/Usuario/UsuarioMudarSenhaPage.aspx");
                }

                if (!Request.RawUrl.Contains("/Admin/Default.aspx") &&
                    !Request.RawUrl.Contains("/Admin/Login/LoginPage.aspx") &&
                    !Request.RawUrl.Contains("/Admin/Seguranca/Usuario/UsuarioMudarSenhaPage.aspx") &&
                    !Request.RawUrl.Contains("/Admin/WinForms") &&
                    !Request.RawUrl.Contains("/Admin/Errors"))
                {

                    SiteMapNode currentNode = SiteMap.CurrentNode;

                    if (currentNode != null && !String.IsNullOrWhiteSpace(currentNode.ResourceKey) && currentNode.ParentNode != null)
                    {

                        UsuarioSiteMapEntity usuarioSiteMap = UsuarioSiteMapBusiness.CreateResourceKey(currentNode.ResourceKey, this.UsuarioId);

                        if (usuarioSiteMap != null)
                        {
                            if (!usuarioSiteMap.Access)
                            {
                                Page.ShowMessage(Mensagens.AcessoNegadoMenu(usuarioSiteMap.SiteMap.TitleParent), "~/Admin/Default.aspx");

                            }
                            else if (!usuarioSiteMap.Usuario.Ativo)
                            {
                                HttpContext.Current.Session.Remove("UsuarioId");
                                FormsAuthentication.SignOut();
                                FormsAuthentication.RedirectToLoginPage();
                            }
                            else
                            {
                                if (String.IsNullOrWhiteSpace(this.Page.Title))
                                {
                                    this.Page.Title = "Devcompy 40 - " + usuarioSiteMap.SiteMap.TitleParent;
                                }
                            }
                        }
                        else
                        {
                            Page.ShowMessage(Mensagens.PaginaNaoEncontrada(), "~/Admin/Default.aspx");


                        }
                    }
                    else
                    {
                        if (this.UsuarioId != 1)
                        {
                            Page.ShowMessage(Mensagens.PaginaNaoEncontrada(), "~/Admin/Default.aspx");
                        }
                    }
                }
            }
        }

        protected void ScriptManager1_AsyncPostBackError(object sender, AsyncPostBackErrorEventArgs e)
        {
            if (e.Exception is DevcompyException)
            {
                Page.ShowMessage(e.Exception.Message);
            }
            else
            {
                new DevcompyException(e.Exception.Message, e.Exception);
                Page.ShowMessage("Ação Inesperada no Sistema <br />" + e.Exception.Message);
            }


        }
    }
}
  • You already wear one on your ContentPlaceHolderID="MainContent" ?

  • See: http://stackoverflow.com/questions/778952/the-controls-collection-cannot-be-modified-because-the-control-contains-code-bl

  • @Pablovargas passes all the code of this page, because, it seems to me that the error is not exactly there in this code, I already test and works normal! Of course there’s a catch ContentPlaceHolderID="MainContent" ! so put all the code .ASPX

  • @Marconi, I’ve tried what’s on that link you sent me.

  • @Dotnet, I don’t quite understand your question.

  • @John is added all the code.

  • Within your Adminbase.Master already has one <asp:ScriptManager ID="ScriptManager1" runat="server">&#xA; </asp:ScriptManager> , this may be causing conflict with your <ajax:ModalPopupExtender ID="ModalPopupExtender1"

  • @Dotnet took the asp:ScriptManager and gave the same error. I created another blank page, without using my Admin.Master and gave no error.

  • @Pablovargas where his reference is on the page?

  • @Marconi reference of the ajax:ModalPopupExtender is in my web.config <add tagPrefix="ajax" namespace="AjaxControlToolkit" assembly="AjaxControlToolkit" />

  • You added? <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>

  • @Pablovargas fuck that there on, Honestly everything that uses this library in my system I’m removing and adding plugins that use Jquery. I have long preferred Jquery, the plugins work much better.

  • @Marconi is a system that at the time I started Ajaxtoolkit was sensation, and I never created shame in the face of migrating to bootstrap and jquery.

Show 8 more comments

2 answers

0

You cannot have <%> when you try to add controls in Runtime. To change the <%> use Code Behind before using the properties for this purpose as the

this.Page.Title = "Ola Mundo";

or adding runat="server tags"

<div runtat="server" ID="myFirstControl"></div> 

and then in code Behind

myFirstControls.InnerHtml = "O meu texto aqui"; 
  • I didn’t see that in his code.

  • What did you not see? Of course this is not an example of correcting his code. Stackoverflow is not a free programming site but a help site. To give an acceptable answer I don’t have to correct the code.

0


The solution for my case was to return the version of Ajaxcontroltoolkit to a version that worked.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.