我现在有三张页面....
一张default.aspx
default.aspx
<%@ Register Src="CityPort.ascx" TagName="CityPort" TagPrefix="uc1" %>
<%@ Register Src="CityPort.ascx" TagName="CityPort" TagPrefix="uc2" %>
<uc1:CityPort ID="CityPort1" runat="server" />
<uc2:CityPort ID="CityPort2" runat="server" />控件里有个tbPort文本框 和img控件.点img控件打开一个showmodal窗口
CityPort.ascx<%@ Control Language="C#" AutoEventWireup="true" CodeFile="CityPort.ascx.cs" Inherits="CityPort" %>
<table width="150" border="0" cellpadding="0" cellspacing="0">
<tr>
<td style="width:130px">
<asp:TextBox ID="tbPort" runat="server" Width="130px"></asp:TextBox>
</td>
<td style="width:20px" valign="bottom">
<img src="images/button_search.gif" 20px" width="18px" id="IMG1" language="javascript" onclick="javascript:window.showModalDialog('port.aspx',window,'status:Modeless;edge:sunken;unadorned:no;scroll=no;resizable:no;dialogLeft:300;dialogtop:200;help:no;dialogwidth:400px;dialogheight:240px');void(0);"/>
</td>
</tr>
</table>port.aspx
<asp:TextBox ID="tbSearch" runat="server"></asp:TextBox>
<asp:Button ID="btnSearch" runat="server" Text="Search" OnClick="btnSearch_Click"/>我现在的问题是点击tbSearch按钮如何把tbsearch的值付给用户控件的tbPort文本框里.
不过这个要通用.比如的用户控件id是CityPort1那么赋值就给cityport1.tbport
如果控件是cityport2那么赋值给CityPort2.tbport 我拖一个控件到CityPort到default.aspx页面id为
Cityport3那么赋值就到针对CityPort3.tbPort里.
这么写够清楚了吧. 不知道该怎么写..如果有源代码做参考最好.不要编译好的dll
一张default.aspx
default.aspx
<%@ Register Src="CityPort.ascx" TagName="CityPort" TagPrefix="uc1" %>
<%@ Register Src="CityPort.ascx" TagName="CityPort" TagPrefix="uc2" %>
<uc1:CityPort ID="CityPort1" runat="server" />
<uc2:CityPort ID="CityPort2" runat="server" />控件里有个tbPort文本框 和img控件.点img控件打开一个showmodal窗口
CityPort.ascx<%@ Control Language="C#" AutoEventWireup="true" CodeFile="CityPort.ascx.cs" Inherits="CityPort" %>
<table width="150" border="0" cellpadding="0" cellspacing="0">
<tr>
<td style="width:130px">
<asp:TextBox ID="tbPort" runat="server" Width="130px"></asp:TextBox>
</td>
<td style="width:20px" valign="bottom">
<img src="images/button_search.gif" 20px" width="18px" id="IMG1" language="javascript" onclick="javascript:window.showModalDialog('port.aspx',window,'status:Modeless;edge:sunken;unadorned:no;scroll=no;resizable:no;dialogLeft:300;dialogtop:200;help:no;dialogwidth:400px;dialogheight:240px');void(0);"/>
</td>
</tr>
</table>port.aspx
<asp:TextBox ID="tbSearch" runat="server"></asp:TextBox>
<asp:Button ID="btnSearch" runat="server" Text="Search" OnClick="btnSearch_Click"/>我现在的问题是点击tbSearch按钮如何把tbsearch的值付给用户控件的tbPort文本框里.
不过这个要通用.比如的用户控件id是CityPort1那么赋值就给cityport1.tbport
如果控件是cityport2那么赋值给CityPort2.tbport 我拖一个控件到CityPort到default.aspx页面id为
Cityport3那么赋值就到针对CityPort3.tbPort里.
这么写够清楚了吧. 不知道该怎么写..如果有源代码做参考最好.不要编译好的dll
解决方案 »
- EXT封装的.NET控件,加载慢
- 求本地大图片上传后按比例缩小然后可以点击查看大图,不生成缩略图。不胜感激
- ASP.NET2.0 下拉式菜单怎么设计呀
- 我的树上有10000多个节点 我是用递归读!很慢!能否改成展开的时候才读子节点!有例子吗?急!!!
- ASP.NET 跟 AJAX
- dataset中多张表导为excel(怎么弄,最好有代码提示下)
- 请教大虾米为什么收不到邮件
- 100分望高手笑纳(求一简单的存储过程)
- 孟子E章的两个文章写的非常不错,可惜是vb的,不知道有没有c#的.孟老大请进.小弟在这里谢过了
- 一般主机提供商,会不会让你用 System.Diagnostics.Process 来启动外部程序
- 关于Image预览图片
- 像csdn社区这样的效果是怎么做出来的啊?
<asp:Image id="Image1" runat="server"></asp:Image> this.Image1.Attributes.Add("onclick","javascript:window.showModalDialog('port.aspx?clientid="+this.TextBox1.ClientID+"',window,'status:Modeless;edge:sunken;unadorned:no;scroll=no;resizable:no;dialogLeft:300;dialogtop:200;help:no;dialogwidth:400px;dialogheight:240px');void(0);");然后,在port.aspx要把得到的参数输出到js
function btnSearch_Click()
{
parent.document.getElementById("这里填入的id是从CityPort.ascx传过来的参数").value = document.getElementById("tbSearch").value;
}
<img src="images/button_search.gif" 20px" width="18px" id="IMG1" language="javascript" onclick="javascript:window.showModalDialog('port.aspx',[window,'<%=tbPort.ClientID%>'],'status:Modeless;edge:sunken;unadorned:no;scroll=no;resizable:no;dialogLeft:300;dialogtop:200;help:no;dialogwidth:400px;dialogheight:240px');void(0);"/>
<asp:TextBox ID="tbSearch" runat="server"></asp:TextBox>
<asp:Button ID="btnSearch" runat="server" Text="Search" OnClick="btnSearch_Click"/>
void btnSearch_Click(...)
{
Page.RegisterStartupScript("SetSearchParameter","<script language=javascript>window.dialogArguments[0].document.getElementById(window.dialogArguments[1]).value ='" + tbSearch.Text + "';</script>");
}
1,控件的客户端ID应该是xx.ClientID进行引用和传递
2,模式窗口可打开它的窗口的关系
参见
http://dotnet.aspx.cc/ShowDetail.aspx?id=49ML4AO8-5PB3-4KNY-NJZD-LJOIOXV4M1X4
3,frame窗口之间的关系
如果真正正确理解了这些个概念,你的问题将很容易解决
<img src="images/button_search.gif" 20px" width="18px" id="IMG1" language="javascript" onclick="javascript:document.getElementById('<%=tbPort.ClientID%>').value = window.showModalDialog('port.aspx',window,'status:Modeless;edge:sunken;unadorned:no;scroll=no;resizable:no;dialogLeft:300;dialogtop:200;help:no;dialogwidth:400px;dialogheight:240px');void(0);"/>
void btnSearch_Click(...)
{
Page.RegisterStartupScript("SetSearchParameter","<script language=javascript>window.returnValue ='" + tbSearch.Text + "'; window.close();</script>");
}
public string PortText
{
get
{
return this.tbPort.Text;
}
set
{
tbPost.Text = value;
}
}port.aspx
btnSearch点击事件
btnSearch_click (object sender, System.EventArgs e)
{
CityPort tmpControl = new CityPort();//创建一个用户控件的实例,这里根据你的情况写
for (int i = 0; i < Form.Controls.Count; i++)//在窗体中循环找控件,用类型比对
{
if (Form.Controls[i].GetType()== tmpControl.GetType())
{
CityPort cp = (CityPort)Form.Controls[i];//引用找到的控件
cp.PortText = tbSearch.Text;//赋值给控件文本框
continue;//如果不跳出,窗体中有多个控件的情况下会给多个控件赋值
}
}
}