首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

。net有关问题

2011-12-29 
。net问题在top.aspx中有个按钮asp:Button IDButton1 runatserver OnClickButton1_Click1 Text

。net问题
在top.aspx中有个按钮<asp:Button ID="Button1" runat="server" OnClick="Button1_Click1" Text="Button" />&nbsp;
<asp:DropDownList
  ID="DropDownList1" runat="server" >
  </asp:DropDownList>
当我点击这个按钮时 protected void Page_Load(object sender, EventArgs e)
  {
  Hashtable ht = (Hashtable)Application["ht"];
  this.DropDownList1.DataSource = ht;
  this.DropDownList1.DataTextField ="key";
  this.DropDownList1.DataValueField = "value";
  this.DropDownList1.DataBind();

   

  if (!IsPostBack)
  {
   
  Button1.Attributes.Add("onClick", "window.showModalDialog(\"showModalDialog.aspx\",\"\",\"dialogWidth:500px;dialogHeight:300px\");");  
  } 
弹出益而高页面对话框是:showModalDialog.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="showModalDialog.aspx.cs" Inherits="test" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">

  <meta http-equiv="Expires" content="0"/> 
<meta http-equiv="Cache-Control" content="no-cache"/> 
<meta http-equiv="Pragma" content="no-cache"/> 
<base target="_self"/>
</head>
<body>
  <form id="form1" runat="server">
  <div>
  &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; &nbsp;&nbsp;
  &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;
  <center> <table >
  <tr>
  <td rowspan="4" style="width: 100px">
  <asp:ListBox ID="ListBox1" runat="server" DataSourceID="SqlDataSource1" DataTextField="CODE_NAME"
  DataValueField="BASE_CODE" Height="197px" Width="185px" BackColor="#E0E0E0" ForeColor="#000040"
  SelectionMode="Multiple"></asp:ListBox></td>
  <td style="width: 58px; height: 44px;">
  </td>
  <td rowspan="4" style="width: 86px">
  <asp:ListBox ID="ListBox2" runat="server" Height="192px" Width="192px" BackColor="LightGray"
  ForeColor="#000040" SelectionMode="Multiple"></asp:ListBox></td>
  </tr>
  <tr>
  <td style="width: 58px;text-align:center; height: 27px;">
  <asp:Button ID="Button" runat="server" Text="添加" Width="56px" OnClick="Button_Click" /></td>
  </tr>
  <tr>
  <td style="width: 58px;text-align:center; height: 19px;">
  <asp:Button ID="Button2" runat="server" Text="删除" Width="55px" OnClick="Button2_Click"/></td>


  </tr>
  <tr>
  <td style="width: 58px; height: 38px;">
  </td>
  </tr>
  </table></center>
   
   
   
  <center> <asp:Button ID="Button3" runat="server" OnClick="Button3_Click" Text="确定" /><br /></center>
  <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:sdeConnectionString %>"
  SelectCommand="SELECT [BASE_CODE], [CODE_NAME] FROM [T_B_C_CODE_DIRECTORY] WHERE (([CODE_LEAF] = @CODE_LEAF) AND ([CODE_LEVEL] = @CODE_LEVEL) AND ([VIEW_CODE] LIKE '%' + @VIEW_CODE + '%')) ORDER BY [BASE_CODE]">
  <SelectParameters>
  <asp:Parameter DefaultValue="1" Name="CODE_LEAF" Type="String" />
  <asp:Parameter DefaultValue="4" Name="CODE_LEVEL" Type="String" />
  <asp:Parameter DefaultValue="003%" Name="VIEW_CODE" Type="String" />
  </SelectParameters>
  </asp:SqlDataSource>
  </div>
  </form>
</body>
</html>
背后代码是using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;

public partial class test : System.Web.UI.Page{

  Hashtable ht;

  protected void Page_Load(object sender, EventArgs e){
  if (!Page.IsPostBack){
  ht = new Hashtable();
  ViewState["ht"] = ht;
  }

  }
   
  protected void Button_Click(object sender, EventArgs e){
  ht= (Hashtable)ViewState["ht"];
  foreach (ListItem i in ListBox1.Items) {
  if (i.Selected == true){
  ListBox2.Items.Add(i.Text);
  ht.Add(i.Text.ToString(), i.Value.ToString());
  } 
  }

  int[] indexToDel = ListBox1.GetSelectedIndices(); //取得所有选取值的index集合
  int cnt = indexToDel.Length;
  for (int i = cnt - 1; i >= 0; i--) {
  ListBox1.Items.RemoveAt(indexToDel[i]);

  }
}
  protected void Button2_Click(object sender, EventArgs e){

  ht = (Hashtable)ViewState["ht"];
  int[] indexToDel = ListBox2.GetSelectedIndices(); //取得所有选取值的index集合
  int cnt = indexToDel.Length;
  foreach(ListItem i in ListBox2.Items){
  if (i.Selected == true) {
  ht.Remove(i.Text.ToString());}
  }

  for (int i = cnt - 1; i >= 0; i--){
  ListBox2.Items.RemoveAt(indexToDel[i]);
  }
  }

  protected void Button3_Click(object sender, EventArgs e){
  ht = (Hashtable)ViewState["ht"];
  Application["ht"] = ht;
   

  Response.Redirect("right_top.aspx");
  Response.Write("<script language=javascript>") ;


  Response.Write("window.returnValue='false';window.close()") ;
  Response.Write("</script>");
  // Response.Write(" <script language=javascript>window.open('right_top.aspx');window.returnValue='True';window.close();</script>"); 

   
  }

}
当我点击Button3_Click 时对话框为什么关不掉,而是出现一个right_top.aspx对话框,我想把right_top.aspx对话框关掉,怎么解决啊?

[解决办法]
点击Button3_Click 时,你想关哪个对话框,不是很明白
"Response.Redirect("right_top.aspx");" 就是重定向到了right_top.aspx,去掉就没有了

热点排行