【问题标题】:Update panel and javascript更新面板和 javascript
【发布时间】:2010-10-13 21:49:36
【问题描述】:

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

<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 中

感谢所有帮助。 谢谢

【问题讨论】:

    标签: asp.net asp.net-ajax updatepanel


    【解决方案1】:

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

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

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

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

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

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

    【讨论】:

    • 这是我的第一个解决方案。问题是数据输入到行(tr2)内的控件中,它们没有正确绑定。我的意思是回发后没有收到数据。我有这个最外面的更新面板之外的下一个按钮。我正在触发自定义事件以取回数据的 Onclick
    猜你喜欢
    • 2011-01-05
    • 2010-11-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-21
    • 1970-01-01
    • 1970-01-01
    • 2011-01-03
    • 1970-01-01
    相关资源
    最近更新 更多