a.aspx
有个控件
<uc1:CityPort ID="CityPort1" runat="server" />控件代码
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
有个textbox1 我现在如何把textbox1的值赋给控件CityPort1里面的tbport

解决方案 »

  1.   

    1.方法一,在你的CityPort.ascx的后面编码里添加一个属性public string Port
    {
       get 
       {
    return tbPort.Text;
       }
       set
       {
    tbPort.Text = value;
       }
    }然后这样赋值CityPort1.Port = textbox1.Text;2.方法二(不推荐),(CityPort1.FindControl("tbPort") as TextBox).Text = textbox1.Text;
      

  2.   

    思归老师.我看了你哪个是在a.aspx里把文本的值付给控件的.我想做的是在port.aspx把值赋给
    CityPort.ascx里的tbPort...
    我用this.btnApply.Attributes.Add("onclick", "window.dialogArguments.document.all.CityPort1.Port='www.sohu.com';window.close();");不可以.对了如果是控件的话那么这个<uc1:CityPort 的id是变化的.那么就不能通用.
    能帮我解决下先谢谢了。.......
      

  3.   

    记得明确说明你的需求先在用户控件里面:
    public TextBox PortTextControl
    {
       get 
       {
          return tbPort;
       }
    }然后:
    this.btnApply.Attributes.Add("onclick", string.Format( "window.dialogArguments.document.all.{0}='www.sohu.com';window.close();" CityPort.PortTextControl.ClientID ));