环境:asp.net,C#。 .Net 4.0,SQL Server 2012
我想在弹出模式窗口中查询数据库。
我试图制作页面。一个是主页面,另一个是子页面,其中包含一个文本框和一个按钮。当我独立运行子页面时,我可以通过单击按钮从数据库中获得文本框中的结果。但是当我将子页面作为主页面中的模型弹出页面时。子页面可以弹出,但单击按钮时没有结果。
我可以遵循任何简单的例子或想法吗?
以下是代码:
主页(popupmother.aspx)
<%@ Page Language="C#" AutoEventWireup="true"
CodeBehind="popupmother.aspx.cs" Inherits="TelerikWebApp1.popupmother" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<telerik:RadScriptManager runat="server" ID="RadScriptManager1" />
<telerik:RadSkinManager ID="RadSkinManager1" runat="server" Skin="Windows7" />
<telerik:RadWindowManager VisibleStatusbar="true" Width="650" Height="500" ReloadOnShow="true"
EnableShadow="true" ID="RadWindowManager1" runat="server" ShowContentDuringLoad="false">
</telerik:RadWindowManager>
<telerik:RadWindow ID="popwin" runat="server" Modal="true" NavigateUrl="popupmodal.aspx"
OpenerElementID="pop" ReloadOnShow="true" Skin="Default">
</telerik:RadWindow>
<asp:Button ID="pop" runat="server" Text="pop" />
</div>
</form>
</body>
</html>
子页面中的(popupmodal.aspx)
<%@ Page Language="C#" AutoEventWireup="true" codeBehind="popupmodal.aspx.cs" Inherits="TelerikWebApp1.popupmodel" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<label>txt1</label>
<asp:TextBox ID="txtbox1" runat="server" Text=""></asp:TextBox>
<asp:Button ID="btnquery" runat="server" Text="query" OnClick="btnquery_Click" />
</div>
</form>
</body>
</html>
子页面代码隐藏
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
namespace TelerikWebApp1
{
public partial class popupmodel : System.Web.UI.Page
{
string myCnnstring = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["EVERGRANDEJYZX1ConnectionString"].ConnectionString;
string mysql;
SqlCommand mycmd;
SqlConnection myCnn;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnquery_Click(object sender, EventArgs e)
{
myCnn = new SqlConnection(myCnnstring);
myCnn.Open();
mysql = "select projectname from BD_Location where pk_location=1";
mycmd = new SqlCommand(mysql, myCnn);
string mytxt = (string)mycmd.ExecuteScalar();
txtbox1.Text = mytxt;
myCnn.Close();
}
}
}