如何从 ASP.NET 中的另一个页面调用 UpdatePanel1.Update() 方法

发布于 2024-12-13 14:01:01 字数 1474 浏览 1 评论 0原文

我有 Default.aspx 和多个控件以及 Uploadify Image 上传控件,我调用另一个文件 UploadImages.aspx 文件来使用 jQuery 上传图像,我使用通用 C# 代码上传图像并将图像详细信息也保存在数据库中。

Default.aspx 页面上的 HTML 代码

<asp:UpdatePanel ID="UpdatePanel1" runat="server" ChildrenAsTriggers="False"  UpdateMode="Conditional">
   <ContentTemplate>                                 
        <asp:DataList ID="DataList1" runat="server" DataSourceID="SqlDataSource1" RepeatDirection="Horizontal" >
            <ItemTemplate>
                <br /><img src='http://test.kashmirsouq.com/ImageUploads/<%# Eval("ImageID") %>' width="100px" height="100px"   vspace="2" hspace="2" border="1" />
                <br /><asp:LinkButton ID="lnkBtnDeleteImage" CommandArgument='<%# Eval("sno") %>' CommandName="Delete" runat="server">
         Delete</asp:LinkButton>
        <br />
            </ItemTemplate>
        </asp:DataList>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            ConnectionString="<%$ ConnectionStrings:SQLConnectionString %>" 
            SelectCommand="SELECT [sno], [ImageID] FROM [User_Images]">
        </asp:SqlDataSource>
 </ContentTemplate>
</asp:UpdatePanel> 

我想使用 UpdatePanel1.Update() 方法来刷新 UpdatePanel1,但我不知道如何在 UploadImage.aspx 页面中注册 updatePanel1 控件。

请帮我解决这个问题 我的基本目标是在上传图像后显示图像而不刷新页面

链接上的页面示例已删除,因为出于安全原因我让它工作

I have Default.aspx with several controls along with Uploadify Image upload control and i am call another file UploadImages.aspx File to upload image using jQuery, I upload images using general C# code and save image details in the database also.

HTML Code on Default.aspx PAGE

<asp:UpdatePanel ID="UpdatePanel1" runat="server" ChildrenAsTriggers="False"  UpdateMode="Conditional">
   <ContentTemplate>                                 
        <asp:DataList ID="DataList1" runat="server" DataSourceID="SqlDataSource1" RepeatDirection="Horizontal" >
            <ItemTemplate>
                <br /><img src='http://test.kashmirsouq.com/ImageUploads/<%# Eval("ImageID") %>' width="100px" height="100px"   vspace="2" hspace="2" border="1" />
                <br /><asp:LinkButton ID="lnkBtnDeleteImage" CommandArgument='<%# Eval("sno") %>' CommandName="Delete" runat="server">
         Delete</asp:LinkButton>
        <br />
            </ItemTemplate>
        </asp:DataList>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            ConnectionString="<%$ ConnectionStrings:SQLConnectionString %>" 
            SelectCommand="SELECT [sno], [ImageID] FROM [User_Images]">
        </asp:SqlDataSource>
 </ContentTemplate>
</asp:UpdatePanel> 

I want to use UpdatePanel1.Update() method To refresh the UpdatePanel1, But i dont know how to register updatePanel1 control in UploadImage.aspx page.

Please help me out with this
My basic object is to show the image once it is upload without refreshing the page

Example of page on link removed as i got it working for security reason

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

尽揽少女心 2024-12-20 14:01:01

尝试使用 uploadify 的 onAllComplete 事件从客户端代码刷新更新面板。为此,添加到页面按钮上,将此按钮的 AsyncPostbackHandler 添加到 updatepanel 的触发器集合中,并在 uploadify onAllComplete 事件处理程序中以编程方式单击此按钮:

$('#fuFiles').uploadify({
    onAllComplete: function (event, data) { $("#<%= HiddenButton.ClientID %>").click(); return true; },
    uploader: 'Scripts/uploadify.swf',
    script: 'FileUploads.aspx',
    cancelImg: 'Scripts/cancel.png',
    auto: 'true',
    multi: 'true',
    buttonText: 'Browse...',
    queueSizeLimit: 5,
    simUploadLimit: 2
});


<asp:Button runat="server" ID="HiddenButton" Style="display: none;" />

<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="false">
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="HiddenButton" />
            </Triggers>

Try to use uploadify's onAllComplete event to refresh your update panel from client-side code. For that purpose add onto the page button, add AsyncPostbackHandler for this button to updatepanel's triggers collection and fire click on this button programmatically in uploadify onAllComplete event handler:

$('#fuFiles').uploadify({
    onAllComplete: function (event, data) { $("#<%= HiddenButton.ClientID %>").click(); return true; },
    uploader: 'Scripts/uploadify.swf',
    script: 'FileUploads.aspx',
    cancelImg: 'Scripts/cancel.png',
    auto: 'true',
    multi: 'true',
    buttonText: 'Browse...',
    queueSizeLimit: 5,
    simUploadLimit: 2
});


<asp:Button runat="server" ID="HiddenButton" Style="display: none;" />

<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="false">
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="HiddenButton" />
            </Triggers>
唱一曲作罢 2024-12-20 14:01:01

ASP.NET WebForms 中的 UpdatePanel 只能用于通过处理来自的同一 aspx 文件来刷新您所在页面的部分内容。因此 Default.aspx 中的 UpdatePanel 将始终返回到 Default.aspx。它根本无法获取另一个页面(例如 UploadImage.aspx)的输出。

您可以通过将 UploadImage.aspx 更改为用户控件并将其包含在 Default.aspx 页面上的更新面板中来解决此问题。

UpdatePanel in ASP.NET WebForms can only be used to refresh parts of the page you're on by processing the same aspx file you came from. So an UpdatePanel in Default.aspx will always go back to Default.aspx. It can't get the output of another page like UploadImage.aspx at all.

You might be able to work around this by changing UploadImage.aspx to a usercontrol, and inlcude that in your updatepanel on the Default.aspx page.

耶耶耶 2024-12-20 14:01:01

我对您的代码 @Yuriy Rozhovetskiy 进行了一些小更改,使其可以正常工作,因为由于某种原因它无法正常工作。功劳归于@Yuriy Rozhovetskiy,所以我将把他的答案标记为正确,下面正在工作&测试版本。

<script type="text/javascript">
    $(document).ready(function () {
        $('#fuFiles').uploadify({
            //'onAllComplete': function (event, data) { $("#<%= HiddenButton.ClientID %>").click(); return true; },
            'uploader': 'Scripts/uploadify.swf',
            'script': 'FileUploads.aspx',
            'cancelImg': 'Scripts/cancel.png',
            'auto': 'true',
            'multi': 'true',
            'fileExt': '*.jpg;*.gif;*.png',
            'buttonText': 'Browse...',
            'queueSizeLimit': 5,
            'simUploadLimit': 2,
            'onAllComplete': function (event, data) 
            {
                $("#<%= HiddenButton.ClientID %>").click();
                return true; 
            }
        });
    });
</script>

        <asp:DataList ID="DataList1" runat="server" DataSourceID="SqlDataSource1" RepeatDirection="Horizontal" >
            <ItemTemplate>
                <br /><img src='http://test.kashmirsouq.com/ImageUploads/<%# Eval("ImageID") %>' width="100px" height="100px"   vspace="2" hspace="2" border="1" />
                <br /><asp:LinkButton ID="lnkBtnDeleteImage" CommandArgument='<%# Eval("sno") %>' CommandName="Delete" runat="server">
         Delete</asp:LinkButton>
        <br />
            </ItemTemplate>
        </asp:DataList>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            ConnectionString="<%$ ConnectionStrings:SQLConnectionString %>" 
            SelectCommand="SELECT [sno], [ImageID] FROM [User_Images]">
        </asp:SqlDataSource>
 </ContentTemplate>
</asp:UpdatePanel> 
<asp:Button runat="server" ID="HiddenButton"  Style="display: none;" onclick="HiddenButton_Click" />

   <div id="fuFiles"></div> 

I got it working with small changes made to your Code @Yuriy Rozhovetskiy as for some reason it was not working. Credit goes to @Yuriy Rozhovetskiy so i will mark his answer as correct, Below is working & tested version.

<script type="text/javascript">
    $(document).ready(function () {
        $('#fuFiles').uploadify({
            //'onAllComplete': function (event, data) { $("#<%= HiddenButton.ClientID %>").click(); return true; },
            'uploader': 'Scripts/uploadify.swf',
            'script': 'FileUploads.aspx',
            'cancelImg': 'Scripts/cancel.png',
            'auto': 'true',
            'multi': 'true',
            'fileExt': '*.jpg;*.gif;*.png',
            'buttonText': 'Browse...',
            'queueSizeLimit': 5,
            'simUploadLimit': 2,
            'onAllComplete': function (event, data) 
            {
                $("#<%= HiddenButton.ClientID %>").click();
                return true; 
            }
        });
    });
</script>

        <asp:DataList ID="DataList1" runat="server" DataSourceID="SqlDataSource1" RepeatDirection="Horizontal" >
            <ItemTemplate>
                <br /><img src='http://test.kashmirsouq.com/ImageUploads/<%# Eval("ImageID") %>' width="100px" height="100px"   vspace="2" hspace="2" border="1" />
                <br /><asp:LinkButton ID="lnkBtnDeleteImage" CommandArgument='<%# Eval("sno") %>' CommandName="Delete" runat="server">
         Delete</asp:LinkButton>
        <br />
            </ItemTemplate>
        </asp:DataList>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            ConnectionString="<%$ ConnectionStrings:SQLConnectionString %>" 
            SelectCommand="SELECT [sno], [ImageID] FROM [User_Images]">
        </asp:SqlDataSource>
 </ContentTemplate>
</asp:UpdatePanel> 
<asp:Button runat="server" ID="HiddenButton"  Style="display: none;" onclick="HiddenButton_Click" />

   <div id="fuFiles"></div> 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文