2017-04-09 2 views
0

In der folgenden Codedatei habe ich Ajax modalen Popup-Code auf Zeile Nr. Geschrieben. 47 Und ich bekomme Fehler, sagend, dass nur eine Instanz von scriptManager der Seite hinzugefügt werden kann, die ich asp.net gerade lerne. Bitte helfen Sie mir, den Fehler zu lösen.System.InvalidOperationException: Nur eine Instanz eines ScriptManager kann der Seite hinzugefügt werden

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Bags.aspx.cs" Inherits="Bags" %> 

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %> 

<!DOCTYPE html> 

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server"> 
<title></title> 
<style> 
.modalBackground { 
     background-color: black; 
     filter: alpha(opacity = 90) !important; 
     opacity: 0.6 !important; 
     z-index: 20; 
    } 

    .modalpopup { 
     padding: 20px 0px 24px 10px; 
     position: relative; 
     width: 450px; 
     height: 66px; 
     background-color: white; 
     border: 1px solid black; 
    } 
</style> 
</head> 
<body> 
<div> 
    <form id="RegistrationsForm" runat="server"> 
     <asp:GridView CssClass="table table-bordered table-striped" ID="GridViewEntry" runat="server" AutoGenerateColumns="False" DataKeyNames="LID" OnSelectedIndexChanged="GridViewEntry_SelectedIndexChanged"> 
      <Columns> 
       <asp:BoundField HeaderText="FULL NAME" DataField="full_name"></asp:BoundField> 
       <asp:BoundField HeaderText="Bag ID" DataField="LID"></asp:BoundField> 
       <asp:BoundField HeaderText="Tag ID" DataField="RFID"></asp:BoundField> 
       <asp:BoundField HeaderText="State" DataField="state"></asp:BoundField> 
       <asp:BoundField HeaderText="At" DataField="At"></asp:BoundField> 
       <asp:TemplateField HeaderText="Action"> 
        <ItemTemplate> 
         <asp:Button ID="LostButton" runat="server" 
          CommandName="Lost" 
          CommandArgument="<%# ((GridViewRow) Container).RowIndex %>" 
          Text="Lost" CssClass="btn btn-sm btn-success" /> 



         <cc1:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"></cc1:ToolkitScriptManager> 




         <asp:Panel ID="Panel1" runat="server" CssClass="modalpopup"> 
          Desription : 
          <br></br> 
          <asp:TextBox ID="Desription" runat="server" placeholder="Optional"></asp:TextBox> 
          <br></br> 
          <asp:Button ID="OK" runat="server" Text="OK" /> 
          <asp:Button ID="Cancel" runat="server" Text="Cancel" /> 
         </asp:Panel> 

         <cc1:ModalPopupExtender ID="ModalPopupExtender1" runat="server" CancelControlID="Cancel" OkControlID="OK" PopupControlID="Panel1" TargetControlID="LostButton" BackgroundCssClass="modalBackground"></cc1:ModalPopupExtender> 


        </ItemTemplate> 
       </asp:TemplateField> 
      </Columns> 
      <EmptyDataTemplate> 
       <div class='row'> 
        <div class='col-sm-12'> 
         <div class='alert alert-warning'> 
          <asp:Label ID="LblError" runat="server">No Information Found! Please Check Again Later!</asp:Label> 

         </div> 
        </div> 
       </div> 
      </EmptyDataTemplate> 

     </asp:GridView> 
    </form> 
</div> 

Bags.aspx.cs

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.UI; 
using System.Web.UI.WebControls; 
using System.Data.SqlClient; 
using System.Data; 

public partial class Bags : System.Web.UI.Page 
{ 
private SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["BAGTRACKConnectionString"].ConnectionString); 
private int fid = 1; 
protected void Page_Load(object sender, EventArgs e) 
{ 
    if ((HttpContext.Current.Session["username"] == null)) 
     Response.Redirect("~/Login.aspx"); 
    if (!IsPostBack) 
    { 
     if (Request.QueryString["ref_id"] != null) 
     { 
      fid = Convert.ToInt32(Request.QueryString["ref_id"]); 
      GVBind(); 

     } 
     else 
     { 
      Response.Redirect("Dashboard.aspx"); 
     } 
    } 
} 

protected void GVBind() 
{ 
    DataSet ds = new DataSet(); 
    con.Open(); 
    SqlCommand cmd = new SqlCommand("select CONCAT(P.fname,' ',P.lname) AS full_name , L.LID ,L.RFID ,S.state ,B.At_time as At from Flight F , Ticket T , Passenger P ,Luggage L , BagTrip B ,Status S where T.FID = F.FID and T.username = P.username and L.TID = T.TID and B.ReaderID = S.ReaderID and B.LID = L.LID and F.FID = @FID ", con); 
    cmd.Parameters.AddWithValue("@FID", fid); 
    SqlDataAdapter da = new SqlDataAdapter(cmd); 
    da.Fill(ds); 
    con.Close(); 
    GridViewEntry.DataSource = ds; 
    GridViewEntry.DataBind(); 
} 



protected void GridViewEntry_SelectedIndexChanged(object sender, EventArgs e) 
{ 

    GridViewRow row = GridViewEntry.SelectedRow; 
    con.Open(); 
    SqlCommand cmd = new SqlCommand("insert into LostRepository values(@LID,0,@desription,@time)", con); 
    cmd.Parameters.AddWithValue("@LID", row.Cells[1]); 
    cmd.Parameters.AddWithValue("@desription", (GridViewEntry.SelectedRow.FindControl("Desription") as TextBox).Text); 
    cmd.Parameters.AddWithValue("@FID", fid); 
    cmd.Parameters.AddWithValue("@time", DateTime.Now.TimeOfDay); 
    cmd.ExecuteNonQuery(); 
    con.Close(); 
} 

}

Antwort

1

Der Fehler trat auf, weil Sie mehr ToolkitScriptManager auf Ihrer Seite haben. Sie haben ToolkitScriptManager in Ihrem GridView Steuerelement platziert, deshalb wird es mehrfach gerendert. Bitte entfernen Sie ToolkitScriptManager von GridView und legen Sie es unter form Tag.

Überprüfen Sie diesen Code:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Bags.aspx.cs" Inherits="Bags" %> 

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %> 

<!DOCTYPE html> 

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server"> 
    <title></title> 
    <style> 
     .modalBackground { 
      background-color: black; 
      filter: alpha(opacity = 90) !important; 
      opacity: 0.6 !important; 
      z-index: 20; 
     } 

     .modalpopup { 
      padding: 20px 0px 24px 10px; 
      position: relative; 
      width: 450px; 
      height: 66px; 
      background-color: white; 
      border: 1px solid black; 
     } 
    </style> 
</head> 
<body> 
    <div> 
     <form id="RegistrationsForm" runat="server"> 

      <cc1:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"></cc1:ToolkitScriptManager> 

      <asp:GridView CssClass="table table-bordered table-striped" ID="GridViewEntry" runat="server" AutoGenerateColumns="False" DataKeyNames="LID" OnSelectedIndexChanged="GridViewEntry_SelectedIndexChanged"> 
       <Columns> 
        <asp:BoundField HeaderText="FULL NAME" DataField="full_name"></asp:BoundField> 
        <asp:BoundField HeaderText="Bag ID" DataField="LID"></asp:BoundField> 
        <asp:BoundField HeaderText="Tag ID" DataField="RFID"></asp:BoundField> 
        <asp:BoundField HeaderText="State" DataField="state"></asp:BoundField> 
        <asp:BoundField HeaderText="At" DataField="At"></asp:BoundField> 
        <asp:TemplateField HeaderText="Action"> 
         <ItemTemplate> 
          <asp:Button ID="LostButton" runat="server" 
           CommandName="Lost" 
           CommandArgument="<%# ((GridViewRow) Container).RowIndex %>" 
           Text="Lost" CssClass="btn btn-sm btn-success" /> 

          <asp:Panel ID="Panel1" runat="server" CssClass="modalpopup"> 
           Desription : 
          <br></br> 
           <asp:TextBox ID="Desription" runat="server" placeholder="Optional"></asp:TextBox> 
           <br></br> 
           <asp:Button ID="OK" runat="server" Text="OK" /> 
           <asp:Button ID="Cancel" runat="server" Text="Cancel" /> 
          </asp:Panel> 

          <cc1:ModalPopupExtender ID="ModalPopupExtender1" runat="server" CancelControlID="Cancel" OkControlID="OK" PopupControlID="Panel1" TargetControlID="LostButton" BackgroundCssClass="modalBackground"></cc1:ModalPopupExtender> 


         </ItemTemplate> 
        </asp:TemplateField> 
       </Columns> 
       <EmptyDataTemplate> 
        <div class='row'> 
         <div class='col-sm-12'> 
          <div class='alert alert-warning'> 
           <asp:Label ID="LblError" runat="server">No Information Found! Please Check Again Later!</asp:Label> 

          </div> 
         </div> 
        </div> 
       </EmptyDataTemplate> 

      </asp:GridView> 
     </form> 
    </div> 
+0

danke das mein Problem gelöst –

+0

Sie sind willkommen !!!!! – csharpbd

Verwandte Themen