如何获取其它页面的返回值,通过文本框接收,在多次取得返回值时,自动累加并排除重复的
主页面要从其它页面获取返回值,显示到文本框里面,在多次取得返回值时,自动累加并排除重复的,我只能每次都刷新空间的值,无法累加,也无法排除重复的
我用的方法是这样的
主页面 a.aspx
<html>
<head runat="server">
<title>无标题页</title>
<script type="text/javascript" language="javascript">
function openwindow()
{
window.open('LeadersSearch.aspx?type=1','', 'height=600, width=400,left=200,top=50,scrollbars=yes');
}
</script>
</head>
<body>
<form id="form1" runat="server">
<input class="text_normal" style="width: 425px;" id="txtRenyuanname" runat="server" />
<input id="btnsel" runat="server" type="button" value="多人参加用,隔开" style="width: 110px"
class="btncss" onclick="openwindow()" />
</form>
</body>
<html>
返回值的页面b.asp
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
<link href="css/style1.css" type="text/css" rel="stylesheet" />
<base target="_self" />
</head>
<body>
<form id="form1" runat="server">
<div style="text-align: center; background-color: #beded5; font-size: 25px; font-weight: bold;
width: 99%;" id="tdtitle">
领导列表
</div>
<table width="99%" border="0">
<tbody>
<tr style="height: 1px">
<td>
</td>
</tr>
</tbody>
</table>
<table class="table_bar" id="Table5" cellspacing="0" cellpadding="2" width="99%">
<tbody>
<tr>
<td nowrap align="right" width="*">
<asp:Button CssClass="button_normal" ID="btnAddRen" runat="server" Text="选定确认" OnClick="btnAdd_Click" />
<asp:Button CssClass="button_normal" ID="btnReturn" runat="server" Text="返回" OnClick="btnReturn_Click" />
</td>
</tr>
</tbody>
</table>
<div>
<asp:GridView ID="gvwShow" OnRowDataBound="gvRowDataBound" CssClass="datagrid_normal"
AutoGenerateColumns="false" DataKeyNames="LeaderID" runat="server">
<SelectedRowStyle CssClass="datagrid_itemstyle_over" />
<AlternatingRowStyle BackColor="#EEEEEE" />
<RowStyle CssClass="datagrid_itemstyle_normal" />
<HeaderStyle CssClass="datagrid_headerstyle_normal" Font-Size="12px" Font-Bold="False"
HorizontalAlign="Center" VerticalAlign="Middle" />
<FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />
<Columns>
<asp:BoundField DataField="LeaderSort" HeaderText="编号"></asp:BoundField>
<asp:BoundField DataField="LeaderName" HeaderText="领导姓名"></asp:BoundField>
<asp:TemplateField HeaderText="选择">
<ItemTemplate>
<asp:CheckBox Font-Size="Smaller" ID="chkSelect" runat="server" />
<asp:TextBox ID="txtName" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"LeaderName") %>'
Visible="false"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
<div class="navbarbot" style="height: 4px">
</div>
</form>
</body>
</html>
返回值页面后台代码
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
BindInfo();
}
}
protected DataTable GetInfo()
{
strSQL = "select case when status =1 then '激活' else '未激活' end status,* ";
strSQL += " from Leaders";
dst1 = db.executeDataSet(strSQL, "table1");
return dst1.Tables["table1"];
}
protected void BindInfo()
{
dtbl1 = GetInfo();
gvwShow.DataSource = dtbl1.DefaultView;
gvwShow.DataBind();
}
//鼠标经过数据行时改变颜色
protected void gvRowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#00A9FF'");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
}
}
private string GetSelectedName(GridView gv1)
{
//取选中的事件编号
string strName = "";
int i, row;
i = 0;
row = gv1.Rows.Count;
CheckBox mycb = new CheckBox();
for (i = 0; i < row; i++)
{
mycb = (CheckBox)gv1.Rows[i].FindControl("chkSelect");
if (mycb != null)
{
if (mycb.Checked)
{
TextBox mytb = new TextBox();
mytb = (TextBox)gv1.Rows[i].FindControl("txtName");
if (mytb != null)
{
strName += mytb.Text.Trim()+",";
}
continue;
}
}
}
return strName;
}
protected void btnAdd_Click(object sender, EventArgs e)
{
string sRenyuanName = GetSelectedName(gvwShow);
if (Request.QueryString["type"].ToString() == "2")
{
Response.Write("<script language=javascript>window.opener.document.all('txtRenyuanname2').value='" + sRenyuanName + "';</SCRIPT>");
}
else
{
Response.Write("<script language=javascript>window.opener.document.all('txtRenyuanname').value='" + sRenyuanName + "';</SCRIPT>");
}
Response.Write("<script language=javascript>window.close();</SCRIPT>");
}
protected void btnReturn_Click(object sender, EventArgs e)
{
Response.Write("<script language=javascript>window.close();</SCRIPT>");
}
[解决办法]
Response.Write(" <script language=javascript>window.opener.document.all('txtRenyuanname2').value='" + sRenyuanName + "'; </SCRIPT>");
[解决办法]
用Session传值吧~
[解决办法]
代码太多了,
做法应该就是每次将原来的TextBox的值加上新得的值,根据分离规则得到一个数组,去掉重复的,然后再进行相加附值给TextBox
string str=TextBox.Text+newValue;
string[] arr=str.split(",");//假如按逗号分隔
List<string> list=new List<string>(); //主要用于判断重复用
string ret=string.Empty;
foreach(string s in arr)
{
if(!string.IsNullOrEmpty(s))
{
if(!list.Contains(s))
{
ret+=s+",";
list.Add(s);
}
}
}
//然后付值给TextBox
textBox.Text=ret;
[解决办法]
Hello,
你可以换一下思路,在打开窗口时用以下方法
function ShowDialogPage(pageAddress,heigh,width)
{
var p_left;
var p_top;
p_left=Math.round((screen.width-300)/2);
p_top=Math.round((screen.height-600)/2);
var returnValue= window.showModalDialog(escape(pageAddress),'','dialogHeight:'+ heigh +'; resizable=no;scroll:no; dialogWidth:'+ width +';dialogTop:'+ p_top +'px;dialogLeft:'+ p_left+'px;')
return returnValue;
}
主要请关注红色部分,即:使用window.showModalDialog()方法,打开一个模式窗口,然后在模式窗口关闭时
使用以下方法返回要返回的值
function CloseDialogAndReturnValue(returnvalue)
{
window.returnValue = returnvalue;
window.close();
}
在父窗口页面获取到值之后,记入一下HiddenField控件或者是一个隐藏的TextBox控件中都可以。
之后再做其他操作,只需获取已记下的值就可以了。