我现在有三张页面....
一张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

解决方案 »

  1.   

    关键是在CityPort.ascx里,要将当前的ClientID传到port.aspx
    <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;
    }
      

  2.   

    parent.window may not workdidn't try, but you could try something likeCityPort.ascx...
    <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>");
    }
      

  3.   

    理解以下几个概念:
    1,控件的客户端ID应该是xx.ClientID进行引用和传递
    2,模式窗口可打开它的窗口的关系
    参见
    http://dotnet.aspx.cc/ShowDetail.aspx?id=49ML4AO8-5PB3-4KNY-NJZD-LJOIOXV4M1X4
    3,frame窗口之间的关系
    如果真正正确理解了这些个概念,你的问题将很容易解决
      

  4.   

    or you could do
    <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>");
    }
      

  5.   

    用户控件的CityPort.ascx.cs文件里面建一个公开的属性,读写tbPort中的数值
    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;//如果不跳出,窗体中有多个控件的情况下会给多个控件赋值
                }
            }
    }