脚本管理器在一页上,但面板在另一页上

发布于 2024-12-12 22:03:41 字数 1511 浏览 0 评论 0原文

我有一个 .Master 页面

   <asp:ScriptManager ID="ScriptManager" runat="server" />
        <asp:UpdatePanel runat="server" id="UpdatePanel" updatemode="Conditional">
            <ContentTemplate>
                <asp:ContentPlaceHolder ID="MasterIndhold_Member" runat="server">
                </asp:ContentPlaceHolder>

,在 ContentPlaceHolder 内我有一个带有 FileUpload 的面板。问题是 FileUpload 找不到该文件。这里我想将RegisterAsyncPostBackControl添加到Scriptmanager中,但是当面板位于另一个页面上时如何执行此操作?

嵌套页面代码如下所示

<asp:Content ID="Content3" ContentPlaceHolderID="MasterIndhold_Member" runat="server">
    <asp:panel runat="server" ID="Panel_MyProfile_Member" Visible="false">
        <asp:FileUpload ID="File1" runat="server" />
            <asp:LinkButton ID="LinkUploadImageMember" runat="server" onclick="LinkUploadImageMember_Click">Upload</asp:LinkButton>

文件上传的代码隐藏如下所示

protected void LinkUploadImageMember_Click(object sender, EventArgs e)
    {
        if (File1.HasFile == true)
        {
            if ((File1.PostedFile.FileName.EndsWith(".jpg")) || (File1.PostedFile.FileName.EndsWith(".jpeg")) || (File1.PostedFile.FileName.EndsWith(".png")))
            {
                    byte[] input = File1.FileBytes;
                    Bruger.UploadImage(input, int.Parse(Request.QueryString["ID"]));
            }
        }
    }

请保留 C# 和 ASP.NET 的代码示例,因为我是这方面的新手 ^^

谢谢

Im having a .Master page with

   <asp:ScriptManager ID="ScriptManager" runat="server" />
        <asp:UpdatePanel runat="server" id="UpdatePanel" updatemode="Conditional">
            <ContentTemplate>
                <asp:ContentPlaceHolder ID="MasterIndhold_Member" runat="server">
                </asp:ContentPlaceHolder>

And inside the ContentPlaceHolder I got an Panel with a FileUpload. The thing is that the FileUpload doesn't find the file. Here I want to add RegisterAsyncPostBackControl to the Scriptmanager, but how do I do this when the panel is on another page?

The nested page code looks like this

<asp:Content ID="Content3" ContentPlaceHolderID="MasterIndhold_Member" runat="server">
    <asp:panel runat="server" ID="Panel_MyProfile_Member" Visible="false">
        <asp:FileUpload ID="File1" runat="server" />
            <asp:LinkButton ID="LinkUploadImageMember" runat="server" onclick="LinkUploadImageMember_Click">Upload</asp:LinkButton>

And the CodeBehind for the FileUpload Looks like this

protected void LinkUploadImageMember_Click(object sender, EventArgs e)
    {
        if (File1.HasFile == true)
        {
            if ((File1.PostedFile.FileName.EndsWith(".jpg")) || (File1.PostedFile.FileName.EndsWith(".jpeg")) || (File1.PostedFile.FileName.EndsWith(".png")))
            {
                    byte[] input = File1.FileBytes;
                    Bruger.UploadImage(input, int.Parse(Request.QueryString["ID"]));
            }
        }
    }

Please keep code examples to C# and ASP.NET as I'm new to this stuff ^^

Thanks

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

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

发布评论

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

评论(1

岁月苍老的讽刺 2024-12-19 22:03:41

您还可以使用 ScriptManagerProxy 类,如果您您的内容页面上需要一个 ScriptManager,但我不确定您是否需要它。您真的需要在每个内容页面上都有一个 UpdatePanel 吗? (因为您在主页上声明了它)。我认为在内容页面中声明 UpdatePanel 可能会更好。

尝试为您的链接按钮定义一个触发器,否则 HasFiles 始终为 false

<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
  <Triggers>
    <asp:PostBackTrigger ControlID="LinkUploadImageMember" />
  </Triggers>

  <ContentTemplate>
    <asp:FileUpload ID="File1" runat="server" />
    <asp:LinkButton ID="LinkUploadImageMember" runat="server" Text=" upload " />
  </ContentTemplate>
</asp:UpdatePanel>

如果您无法从母版页中删除 UpdatePanel,您可以在母版页上公开一个允许访问更新面板的属性,如下所示:

public UpdatePanel MyUpdatePanel 
{
    get { return UpdatePanel1; }
}

从内容页您可以访问更新面板并以编程方式更新触发器:

protected void Page_Load(object sender, EventArgs e)
{
        ((Site)Master).MyUpdatePanel.Triggers.Add(new PostBackTrigger() {
              ControlID = LinkUploadImageMember.UniqueID });
}

You could also use the ScriptManagerProxy class if you need a ScriptManager on your content page, but I'm not sure whether you need this at all. Do you really need an UpdatePanel on every content page? (because you declared it on the master page). I think it might be better to declare the UpdatePanel within the content page.

Try to define a trigger for your linkbutton, otherwise HasFiles is always false

<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
  <Triggers>
    <asp:PostBackTrigger ControlID="LinkUploadImageMember" />
  </Triggers>

  <ContentTemplate>
    <asp:FileUpload ID="File1" runat="server" />
    <asp:LinkButton ID="LinkUploadImageMember" runat="server" Text=" upload " />
  </ContentTemplate>
</asp:UpdatePanel>

If you cannot remove the UpdatePanel from the Masterpage, you could expose a property on the masterpage that gives access the updatepanel, like this:

public UpdatePanel MyUpdatePanel 
{
    get { return UpdatePanel1; }
}

From the contentpage you can access the update panel and update the triggers programmatically:

protected void Page_Load(object sender, EventArgs e)
{
        ((Site)Master).MyUpdatePanel.Triggers.Add(new PostBackTrigger() {
              ControlID = LinkUploadImageMember.UniqueID });
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文