我无法使用ScriptManager从后面的代码生成模式
我已经尝试运行脚本,一切正常,但是问题是当我使用$('#myModal')。modal('show')函数时。
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/AdminPage.Master" AutoEventWireup="true" CodeBehind="AdminView.aspx.cs" Inherits="HotelReservation.Views.AdminView" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<script type="text/javascript">
function openModal() {
alert("hi");
$('#myModal').modal('show');
}
</script>
<style>
.hiddencol {
display:none;
}
</style>
<asp:GridView ID="GridView1" CssClass="table table-bordered" runat="server" OnRowCommand="GridView1_RowCommand" DataKeyNames="HotelID">
<AlternatingRowStyle BackColor="White" ForeColor="#284775"></AlternatingRowStyle>
<Columns>
<asp:ButtonField CommandName="detail"
ControlStyle-CssClass="btn btn-info" ButtonType="Button"
Text="Detail" HeaderText="Detailed View" />
<asp:BoundField ItemStyle-CssClass="hiddencol" HeaderStyle-CssClass="hiddencol" DataField="HotelID" />
<asp:BoundField ItemStyle-CssClass="hiddencol" HeaderStyle-CssClass="hiddencol" DataField="HotelName" />
<asp:BoundField ItemStyle-CssClass="hiddencol" HeaderStyle-CssClass="hiddencol" DataField="Location" />
<asp:BoundField ItemStyle-CssClass="hiddencol" HeaderStyle-CssClass="hiddencol" DataField="TotalDeluxe" />
<asp:BoundField ItemStyle-CssClass="hiddencol" HeaderStyle-CssClass="hiddencol" DataField="PriceOfDeluxe" />
<asp:BoundField ItemStyle-CssClass="hiddencol" HeaderStyle-CssClass="hiddencol" DataField="TotalSuperDeluxe" />
<asp:BoundField ItemStyle-CssClass="hiddencol" HeaderStyle-CssClass="hiddencol" DataField="PriceOfSuperDeluxe" />
<asp:BoundField ItemStyle-CssClass="hiddencol" HeaderStyle-CssClass="hiddencol" DataField="TotalSuite" />
<asp:BoundField ItemStyle-CssClass="hiddencol" HeaderStyle-CssClass="hiddencol" DataField="PriceOfSuite" />
</Columns>
</asp:GridView>
<asp:HiddenField runat="server" ID="hiddenprimary"/>
<div class="modal fade" runat="server" id="myModal" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Hotel CRUD</h4>
</div>
<div class="modal-body">
<fieldset>
<div class="form-group">
<label class="col-lg-2 control-label" for="hotelprimary">HotelID: </label>
<div class="col-lg-10">
<input class="form-control" id="hotelprimary" readonly="readonly" runat="server" type="text" />
</div>
</div>
<div class="form-group">
<label class="col-lg-2 control-label" for="hotelname">HotelName: </label>
<div class="col-lg-10">
<input class="form-control" id="hotelname" runat="server" type="text" />
</div>
</div>
<div class="form-group">
<label class="col-lg-2 control-label" for="location">location: </label>
<div class="col-lg-10">
<input class="form-control" id="location" runat="server" type="text" />
</div>
</div>
<div class="form-group">
<label class="col-lg-2 control-label" for="totalDeluxe">TotalDeluxe: </label>
<div class="col-lg-10">
<input class="form-control" id="totalDeluxe" runat="server" type="text" />
</div>
</div>
<div class="form-group">
<label class="col-lg-2 control-label" for="PriceOfDeluxe">PriceOfDeluxe: </label>
<div class="col-lg-10">
<input class="form-control" id="PriceOfDeluxe" runat="server" type="text" />
</div>
</div>
</fieldset>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-success" data-dismiss="modal">Close</button>
<asp:Button ID="Button1" runat="server" Text="Update" CssClass="btn btn-primary" />
<asp:Button ID="Button2" runat="server" Text="Delete" CssClass="btn btn-warning" />
</div>
</div>
</div>
</div>
<button type="button" class="btn btn-success btn-lg" data-toggle="modal" data-target="#add">Add Hotel</button>
<!-- Modal -->
<div class="modal" runat="server" id="add" role="dialog">
<div class="modal-dialog" role="document">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Hotel CRUD</h4>
</div>
<div class="modal-body">
<fieldset>
<div class="form-group">
<label class="col-lg-2 control-label" for="HotelID1">HotelID: </label>
<div class="col-lg-10">
<input class="form-control" id="HotelID1" readonly="readonly" runat="server" type="text" />
</div>
</div>
<div class="form-group">
<label class="col-lg-2 control-label" for="hotelname1">hotelname: </label>
<div class="col-lg-10">
<input class="form-control" id="hotelname1" runat="server" type="text" />
</div>
</div>
<div class="form-group">
<label class="col-lg-2 control-label" for="location1">location: </label>
<div class="col-lg-10">
<input class="form-control" id="location1" runat="server" type="text" />
</div>
</div>
<div class="form-group">
<label class="col-lg-2 control-label" for="totalDeluxe1">totalDeluxe: </label>
<div class="col-lg-10">
<input class="form-control" id="totalDeluxe1" runat="server" type="text" />
</div>
</div>
<div class="form-group">
<label class="col-lg-2 control-label" for="PriceOfDeluxe1">PriceOfDeluxe1: </label>
<div class="col-lg-10">
<input class="form-control" id="PriceOfDeluxe1" runat="server" type="text" />
</div>
</div>
</fieldset>
</div>
<div class="modal-footer">
<asp:Button ID="Button3" runat="server" Text="ADD" CssClass="btn btn-primary" />
</div>
</div>
</div>
</div>
</ContentTemplate>
</asp:UpdatePanel>
在那之后检查我的代码后面
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HotelBAL;
using System.Data;
namespace HotelReservation.Views
{
public partial class AdminView : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
GridView1.DataSource = HotelBal.getAllHotelDetails();
GridView1.DataBind();
}
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName.Equals("detail"))
{
int index = Convert.ToInt32(e.CommandArgument);
string hotelID = GridView1.DataKeys[index].Value.ToString();
DataTable ds= HotelBal.getAllHotelDetails();
var query = from row in ds.AsEnumerable()
where row.Field<int>("HotelID")==(Convert.ToInt32(hotelID))
select row
;
foreach (var x in query)
{
hotelprimary.Value = hotelID;
hotelname.Value =x[1].ToString();
location.Value = x[2].ToString();
totalDeluxe.Value = x[3].ToString();
PriceOfDeluxe.Value = x[4].ToString();
}
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "step1confirm", "openModal();", true);
//ScriptManager.RegisterStartupScript(this, GetType(), "YourUniqueScriptKey",
//"alert('This pops up');", true);
}
}
}
}