找到你要的答案

Q:How to query database in modal popup window

Q:如何在模态窗口的数据库查询

Environment: asp.net, C#. .Net 4.0, SQL Server 2012

I want to query database in popup modal window.

I tried to make to pages. one is the Main page, the other is Child page, which contains a textbox and a button. When I run the child page independently, I could get result in the textbox from database by clicking the button. But when I make the child page as model popup page in the main page. The child page can popup, but no result when button clicked.

Is there any simple example or idea I can follow?

Here is the code:

main page(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>

in the child page (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>

child page code-behind

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();
       }
    }
}

环境:ASP.NET、C #。4、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();
       }
    }
}
c#  asp.net  sql-server-2012