2

我有一个用户控件,其结构是 -

<updatepanel UpdateMode="Always">
<ContentTemplate>
   <asp:FormView>
    <EditItemTemplate>
       <table>
           <tr id='tr1'>
             <td>
                 Textbox1
                 btn1
             </td> 
           </tr> 
           <tr id='tr2'>
             <td>
                  textbox2
             </td> 
           </tr> 
        <table>
   </EditItemTemplate>
  </asp:FormView>
</ContentTemplate>
</updatepanel>

在页面加载时,我使用以下来隐藏 tr2

ClientScriptManager cs = Page.ClientScript;
csText.AppendLine("");
csText.AppendLine("if(document.getElementById('tr2')!=null) 
           document.getElementById('tr2').style.display = 'none';");
csText.AppendLine("");
cs.RegisterStartupScript(this, this.GetType(), csName, csText.ToString(), false); 

这部分工作正常。现在点击 btn1 我弹出模态弹出扩展控件。这会导致 tr2 再次显示。我知道脚本需要与 updatePanel 内联。我尝试使用ScriptManager.RegisterStartupScript(....);但不起作用。此外 updateMode 需要始终如此,以便可以将来自 pop 扩展器的数据放入 Textbox1

感谢所有帮助。谢谢

4

1 回答 1

0

由于您使用的是 UpdatePanel,因此您实际上不需要任何 javascript。

如果您将 tr2 元素更改为...

<tr id="tr2" runat="server">

这将允许您在服务器端代码中控制它。要隐藏您的 tr2 行,只需执行...

tr2.Style["display"] = "none";

这应该在回调中很好地保持同步。

于 2009-03-17T18:01:36.033 回答