如何从 ASP.NET 中的另一个页面调用 UpdatePanel1.Update() 方法
我有 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试使用 uploadify 的
onAllComplete
事件从客户端代码刷新更新面板。为此,添加到页面按钮上,将此按钮的 AsyncPostbackHandler 添加到 updatepanel 的触发器集合中,并在 uploadify onAllComplete 事件处理程序中以编程方式单击此按钮: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: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.
我对您的代码 @Yuriy Rozhovetskiy 进行了一些小更改,使其可以正常工作,因为由于某种原因它无法正常工作。功劳归于@Yuriy Rozhovetskiy,所以我将把他的答案标记为正确,下面正在工作&测试版本。
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.