更新面板和Repeater控件触发 [英] Update Panel and triggers from a repeater control

查看:137
本文介绍了更新面板和Repeater控件触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我发现code类同网上以下。这看起来真的很棒获取埋藏在一个中继器控制按钮,触发一个完整的周期回服务器。

Hi I found code similiar to the following online. It's seems really great for getting a button buried in a repeater control to trigger a full cycle back to the server.

<asp:ScriptManager ID="ScriptManager1" runat="server"> 
        </asp:ScriptManager> 

        <asp:UpdatePanel ID="UpdatePanel1" runat="server"> 
            <ContentTemplate> 
                <%=DateTime.Now.ToString() %> 
            </ContentTemplate> 
            <Triggers> 
                <asp:PostBackTrigger ControlID="HiddenButton" /> 
            </Triggers> 
        </asp:UpdatePanel> 

        <!--Make a hidden button to treat as the postback trigger--> 
        <asp:Button ID="HiddenButton" runat="server" Style="display: none" Text="HiddenButton" /> 


        <asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1"> 
            <ItemTemplate> 
                 <!--when cick the button1, it will fire the hiddenButton--> 
                <asp:Button ID="Button1" Text="Trigger" CommandArgument='<%# Eval("Id") %>' OnClientClick="$get('HiddenButton').click();return false;" 
                    runat="server" /> 
            </ItemTemplate> 
        </asp:Repeater>

它采用了hiddenButton通过挂钩原有按钮的Click事件这一个实现这一目标。但是我除了这是CommandArgument为按钮的设置。我还需要它来为HiddenButton进行设置。

It uses a hiddenButton to achieve this by hooking the click event of the original button to this one. However my addition to this was the setting of the CommandArgument for the button. I would also need it to be set for the HiddenButton.

有谁知道要对这个办法?

Does anyone know a way of going about this?

推荐答案

首先,我会想解释缺点使用更新面板<中 / code>使用您发布的非常相同的例子。

First I will like to explain the Disadvantage of using the Update Panel using the very same example posted by you.

要显示22字符的字符串,您可以检查被多少数据接收和发送到服务器。试想以下

To display the 22 character string you can check how much data is being received and sent to server. Just imagine following


  1. 如果您会考虑每个请求发送到数据库使用更新面板和您的的GridView 更新面板 !!!!!!

  2. 假设你会使用的ViewState 数据为每个请求,并与 GridView中更新面板
  3. 里面
  1. If you would consider send each request to Database using Update Panel and your GridView is in Update Panel!!!!!!
  2. Suppose you would use ViewState data for each request and with GridView Inside the Update Panel.

以上两种方法是最糟糕的按我的理解。

Both the above techniques are worst as per my understanding.

现在我将描述页方法

页方法允许 ASP.NET AJAX 页面直接执行页的静态方法,使用 JSON(JavaScript对象符号)。相反,回发,然后接收HTML标记来完全替代我们的的UpdatePanel的内容,我们可以使用 Web方法只请求我们感兴趣的信息。

Page Methods allow ASP.NET AJAX pages to directly execute a Page’s Static Methods, using JSON (JavaScript Object Notation). Instead of posting back and then receiving HTML markup to completely replace our UpdatePanel’s contents, we can use a Web Method to request only the information that we’re interested.


希望这清楚地说明用法的区别。

Hope this clearly explains the difference of usage.

您必须先注册低于转发的的的ItemDataBound 事件并使用下面code吧。

You have to register the ItemDataBound event of the below Repeater and use below code for it.

protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
    if (e.Item.ItemType == ListItemType.Item || 
                           e.Item.ItemType == ListItemType.AlternatingItem)
    {
        Button btn = (Button)e.Item.FindControl("Button1");
        btn.OnClientClick = string.Format("SubmitButton('{0}');return false;"
                                                        , HiddenButton.ClientID);

    }
}


的JavaScript

<script type="text/javascript">
     function SubmitButton(btn)
     {
         $("#" + btn).click(); 
     }
</script>

//替代

<script type="text/javascript">
     function SubmitButton(btn)
     {
         document.getElementById(btn).click(); 
     }
</script>


<一个href=\"http://msdn.microsoft.com/en-us/library/system.web.ui.updatepanel.rendermode.aspx\">Reference &安培; 这里


Reference & Here

这篇关于更新面板和Repeater控件触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆