• 隐藏iframe实现无刷新的效果


    有时候没办法要用到的微软的一些服务器端的控件,如gridview,这时候如果你想获取这个控件里面的值的话,又不想刷新整个页面,这时候隐藏的iframe就可以用上场了。

    实现的原理很简单,就是在form里面将target="iframename" 赋值与隐藏的iframe的name相等,就可以调用服务器端控件直接在asp.cs页面里面的方法了,但是刷新的是隐藏的iframe,所以你看不到页面的刷新。

    简单代码演示:

    <iframe name="iframename" style="display:none;"></iframe>

    <form runat="server" method="post" enctype="multipart/form-data"   target="iframename" onsubmit="return save(this)">

    <table >
     <tr>
     <asp:GridView ID="GridView1" runat="server" AllowSorting="True" AutoGenerateColumns="False" OnRowDataBound="GridView1_RowDataBound"  DataKeyNames="Fid,FMask"  >
                                        <Columns>
                                        <asp:BoundField DataField="Group" HeaderText="模块" ReadOnly="True" >
                                            <ItemStyle HorizontalAlign="Left" Width="200px" />
                                        </asp:BoundField>
                                        <asp:BoundField DataField="FName" HeaderText="功能列表" ReadOnly="True" >
                                            <ItemStyle HorizontalAlign="Left" />
                                        </asp:BoundField>
                                        <asp:BoundField DataField="FObjectDetailDesc" HeaderText="操作" ReadOnly="True" >
                                            <ItemStyle HorizontalAlign="Left" Width="150px" />
                                        </asp:BoundField>
                                        <asp:TemplateField meta:resourcekey="TemplateFieldResource1">
                                            <HeaderTemplate>
                                                <asp:Label ID="lbAuthorize" runat="server" Text="授权" ></asp:Label>
                                                <asp:CheckBox ID="chkSelectAll" runat="server" onclick="selectAll(this)"  />
                                            </HeaderTemplate>
                                            <ItemTemplate>
                                                <asp:CheckBox ID="chkSelect" runat="server" Text=" " />
                                            </ItemTemplate>
                                            <ItemStyle Width="120px" />
                                            <HeaderStyle Width="120px" />
                                        </asp:TemplateField>
                                    </Columns>
                                    <RowStyle HorizontalAlign="Left" />
                                </asp:GridView>

    </tr>

    <tr> <asp:Button ID="btnSave" runat="server"     OnClick="lbnSave_Click"  /></tr>
      </table>
    </form>

    asp.cs代码

    protected void lbnSave_Click(object sender, EventArgs e)
        {

                        foreach (GridViewRow row in GridView1.Rows)
                        {
                            cb = (CheckBox)row.FindControl("chkSelect");
                            //在这里就可以尽情地玩转那该死的gridview控件啦,但是在页面上却看不到刷新的效果的

                           //

                  
              

                         }
     
        }

    这种方法同样适用于嵌入不完整的页面的局部刷新的适用

  • 相关阅读:
    Leetcode86.分隔链表
    Leetcode39.组合总和
    Leetcode31.下一个排列
    剑指Offer35.复杂链表复制
    剑指Offer14-I.剪绳子
    剑指Offer38.字符串的排序
    Leetcode29.两数相除
    232. Implement Queue using Stacks
    程序员跳槽指南
    226. Invert Binary Tree
  • 原文地址:https://www.cnblogs.com/linzheng/p/1867614.html
Copyright © 2020-2023  润新知