Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7846081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T17:27:37+00:00 2026-06-02T17:27:37+00:00

I am dynamically adding usercontrols to my page: when the user clicks on the

  • 0

I am dynamically adding usercontrols to my page:

  • when the user clicks on the button, jquery ajax method executes, which calls my web method
  • the web method returns my usercontrol rendered as string
  • in the success part of ajax call the received html is appended to a placeholder

Method to render my usercontrol:

public static string RenderUserControlAsString(string path)
{
    var page = new PageOverride();
    var viewControl = (UserControl)page.LoadControl(path);
    page.Controls.Add(viewControl);
    var output = new StringWriter();
    HttpContext.Current.Server.Execute(page, output, true);
    return output.ToString();
}

This works OK, but I have problems with ImageUrl of my asp:Image element (my usercontrol contains multiple elements and asp:Image is just one of them):

<asp:Image ID="imgDelete" runat="server" ImageUrl="~/images/delete.gif" onmouseover="this.style.cursor='hand'" onmouseout="this.style.cursor='default'"/>

The ImageUrl gets transformed to ../images/delete.gif, which is not OK. Actially, the ImageUrl always receives two dots and a slash infront of it. Any ideas how to prevent that?

Edit – project structure:

Root:

  • images
    • delete.gif
    • …
  • WebControls
    • MyWebControl.ascx
    • …
  • MyWebService.asmx
  • MyPage.aspx
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T17:27:39+00:00Added an answer on June 2, 2026 at 5:27 pm

    For now I just added an override method to my web control:

    protected override void OnPreRender(EventArgs e)
    {
          base.OnPreRender(e);
    
          // Don't use ImageUrl, set fixed src attribute.
          imgDelete.Attributes["src"] = "images/delete.gif";
    }
    

    The drawback is, that the image is displayed only on pages, which reside in root folder, but that works for me.

    Another way would be with jquery livequery plugin:

    $('.Delete').livequery(function () {
        $(this).attr('src', 'images/delete.gif');
    });
    

    Edit – I could probably also set CssClass to the image button and set background: url(../images/add.gif) with css…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I’m adding web user controls to a page dynamically. Using the LoadControl method that
i have a aspx page on it i'm dynamically adding the web user controls
I'm dynamically adding a h:selectOneMenu to the page. But the listener method for f:ajax
I'm dynamically loading user controls adding them to the Controls collection of the web
I am dynamically adding inputs to a form when a user clicks on an
I am currently dynamically adding content to the page with the help of Jquery.
I am dynamically adding X canvas elements to a page via jQuery like so:
I'm dynamically adding a custom user control to the page as per this post
I have created user control container (panel actually) which dynamically adding and removing user
I have an ASP.NET web form which I am adding a variable number User

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.