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

  • Home
  • SEARCH
  • 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 8819739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:26:18+00:00 2026-06-14T05:26:18+00:00

I am trying to set asp image element src property from javascript but the

  • 0

I am trying to set asp image element src property from javascript but the url property is not being set.

function slideshow() {
  $.ajax({
    type: "POST",
    contentType: "application/json; charset=utf-8",
    url: "/RollingScreen.aspx/GetNextImage",
    dataType: "json",
    data: "{}",
    success: function (data) {
      //this changes the image on the web page
      $('#imgSlideShow').attr("src","~/1.png");
      $("#txt1").val(data.d);
      //fires another sleep/image cycle
      setTimeout(slideshow,5000);
    },
    error: function (result) {
      alert(result.message);
    }
  });
}

$(document).ready(function () {
  //Kicks the slideshow
  slideshow();
});

My aspx image element is

<asp:Image ID="imgSlideShow" runat="server" Height="300px" Width="600px" ImageAlign="Middle" ImageUrl="~/1.png"/>....

Can anyone please help me…

  • 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-14T05:26:20+00:00Added an answer on June 14, 2026 at 5:26 am

    Your mistake is that you are trying to use ID which you have set in asp.net. But runat=”server” elements are rendered with different IDs. Something like Content1_Content2_imgSlideShow. You can get it using imgSlideShow.ClientID on server side and than $('#' + jsVariableWithClientID). But I prefer to use some unique class (no problem with passing client ID to JS):

    <asp:Image ID="imgSlideShow" CssClass="imgSlideShow" runat="server" Height="300px" Width="600px" ImageAlign="Middle" ImageUrl="~/1.png"/>

    And than in JS, using class selector:

    $('.imgSlideShow').attr("src","/1.png");
    

    Another problem is that JS does not know about ~ – that is asp.net feature only. And you should specify image url for src like this: "/1.png" (assuming it is located in root directory)

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

Sidebar

Related Questions

I am trying to create a slideshow using Javascript and an asp.net image control.
I'm trying to set the port on a cookie in ASP.NET (code below), but
Am trying to set a new date for Calendar object on ASP.NET , but
I am trying to set my gridview (asp.net) position to absolute when the gridview
I am trying to set the style of an asp:TextBox in codebehind, the textbox
In ASP.NET MVC3 I'm trying to set the css class that the validation error
I'm trying to set up a messages view with asp.net mvc that will display
I'm trying to set my default page to Index.html on an ASP.NET site running
Hello I been trying to figure out how to set up ASP.Net forms authentication
I am trying to build set of reusable components for the ASP.Net MVC3 application.

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.