Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Displaying Image in ASP.NET AJEX

Displaying Image in ASP.NET AJEX

Scheduled Pinned Locked Moved ASP.NET
csharphtmlasp-netdatabasesysadmin
14 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bapu2889
    wrote on last edited by
    #1

    Hello all I am working on my one of my assignment to create ASP.NET AJAX project it's simple with one default.aspx page and on the middle of page there is one updatepanel and inside UpdatePanel there is on ImageBox and one Timer I have one Image folder and there are 16 images and i want to display image in to imagebox in order from 1 to 16 and after 16th image it goes to image 1 and so on this is what i have done so far and it's working ok but still i want to do some thing in it

    Dim MyImage(15) As String
    Private Sub GetImages()
        MyImage(0) = "1.png"
        MyImage(1) = "2.png"
        MyImage(2) = "3.png"
        MyImage(3) = "4.png"
        MyImage(4) = "5.png"
        MyImage(5) = "6.png"
        MyImage(6) = "7.png"
        MyImage(7) = "8.png"
        MyImage(8) = "9.png"
        MyImage(9) = "10.png"
        MyImage(10) = "11.png"
        MyImage(11) = "12.png"
        MyImage(12) = "13.png"
        MyImage(13) = "14.png"
        MyImage(14) = "15.png"
        MyImage(15) = "16.png"
    End Sub
    
    Sub GetNextImage(ByVal Src As Object, ByVal Args As EventArgs)
        'Retrieve the array from view state
        MyImage = ViewState("PictureArray")
    
        'Increment the image counter
        ViewState("Counter") += 1
        If ViewState("Counter") > 15 Then
            ViewState("Counter") = 0
        End If
    
        'Assign the next image to the control
        BannerImage.ImageUrl = MyImage(ViewState("Counter"))
    End Sub
    Protected Sub Page\_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    
        If Not Page.IsPostBack Then
            '--Load as array with image ursl and save to view state
            Call GetImages()
            ViewState("PictureArray") = MyImage
    
            '--Establish a counter to keep track of the array index
            ViewState("Counter") = 0
            BannerImage.ImageUrl = MyImage(ViewState("Counter"))
        End If
    End Sub
    

    and HTML is like <asp:UpdatePanel ID="BannerUpdatePanel" runat="server"> <Triggers> <asp:AsyncPostBackTrigger ControlID="Timer2" /> </Triggers> <ContentTemplate> <asp:Timer ID="Timer2" runat="server" Interval="250" OnTick="GetNextImage"> </asp:Timer> <br /> <asp:Image ID="BannerImage" runat="server" ImageUrl="~/G

    N 1 Reply Last reply
    0
    • B bapu2889

      Hello all I am working on my one of my assignment to create ASP.NET AJAX project it's simple with one default.aspx page and on the middle of page there is one updatepanel and inside UpdatePanel there is on ImageBox and one Timer I have one Image folder and there are 16 images and i want to display image in to imagebox in order from 1 to 16 and after 16th image it goes to image 1 and so on this is what i have done so far and it's working ok but still i want to do some thing in it

      Dim MyImage(15) As String
      Private Sub GetImages()
          MyImage(0) = "1.png"
          MyImage(1) = "2.png"
          MyImage(2) = "3.png"
          MyImage(3) = "4.png"
          MyImage(4) = "5.png"
          MyImage(5) = "6.png"
          MyImage(6) = "7.png"
          MyImage(7) = "8.png"
          MyImage(8) = "9.png"
          MyImage(9) = "10.png"
          MyImage(10) = "11.png"
          MyImage(11) = "12.png"
          MyImage(12) = "13.png"
          MyImage(13) = "14.png"
          MyImage(14) = "15.png"
          MyImage(15) = "16.png"
      End Sub
      
      Sub GetNextImage(ByVal Src As Object, ByVal Args As EventArgs)
          'Retrieve the array from view state
          MyImage = ViewState("PictureArray")
      
          'Increment the image counter
          ViewState("Counter") += 1
          If ViewState("Counter") > 15 Then
              ViewState("Counter") = 0
          End If
      
          'Assign the next image to the control
          BannerImage.ImageUrl = MyImage(ViewState("Counter"))
      End Sub
      Protected Sub Page\_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
      
          If Not Page.IsPostBack Then
              '--Load as array with image ursl and save to view state
              Call GetImages()
              ViewState("PictureArray") = MyImage
      
              '--Establish a counter to keep track of the array index
              ViewState("Counter") = 0
              BannerImage.ImageUrl = MyImage(ViewState("Counter"))
          End If
      End Sub
      

      and HTML is like <asp:UpdatePanel ID="BannerUpdatePanel" runat="server"> <Triggers> <asp:AsyncPostBackTrigger ControlID="Timer2" /> </Triggers> <ContentTemplate> <asp:Timer ID="Timer2" runat="server" Interval="250" OnTick="GetNextImage"> </asp:Timer> <br /> <asp:Image ID="BannerImage" runat="server" ImageUrl="~/G

      N Offline
      N Offline
      Not Active
      wrote on last edited by
      #2

      Really you don't even need AJAX to do this, simple JavaScript will handle this

      var imageNum = 1;

      setInterval(changeImage, 250);

      function changeImage()
      {
      if( imageNum >= 16 )
      imageNum = 1;

      img.src = "http:\\mysite\" + imageNum + ".png";
      imageNum++;
      }


      only two letters away from being an asset

      modified on Tuesday, October 27, 2009 7:55 AM

      B 1 Reply Last reply
      0
      • N Not Active

        Really you don't even need AJAX to do this, simple JavaScript will handle this

        var imageNum = 1;

        setInterval(changeImage, 250);

        function changeImage()
        {
        if( imageNum >= 16 )
        imageNum = 1;

        img.src = "http:\\mysite\" + imageNum + ".png";
        imageNum++;
        }


        only two letters away from being an asset

        modified on Tuesday, October 27, 2009 7:55 AM

        B Offline
        B Offline
        bapu2889
        wrote on last edited by
        #3

        Hello sir Thanks for your rep. sir I dont know JS and C# so any other help I have tried to change this to vb but i am bit strugling with 2 things 1- setInterval(changeImage, 250); 2- img.src = waiting for your kind rep. thanks

        C A 2 Replies Last reply
        0
        • B bapu2889

          Hello sir Thanks for your rep. sir I dont know JS and C# so any other help I have tried to change this to vb but i am bit strugling with 2 things 1- setInterval(changeImage, 250); 2- img.src = waiting for your kind rep. thanks

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          bapu2889 wrote:

          sir I dont know JS and C# so any other help

          You should buy some books and read them

          bapu2889 wrote:

          I have tried to change this to vb

          NONE of it is C#, it is javascript and cannot be changed to VB. Use it exactly as is. Buy a book. Please.

          Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

          1 Reply Last reply
          0
          • B bapu2889

            Hello sir Thanks for your rep. sir I dont know JS and C# so any other help I have tried to change this to vb but i am bit strugling with 2 things 1- setInterval(changeImage, 250); 2- img.src = waiting for your kind rep. thanks

            A Offline
            A Offline
            Abhishek Sur
            wrote on last edited by
            #5

            A slight modification :

            var imageNum = 1;

            setInterval("changeImage()", 250);

            function changeImage()
            {
            if( imageNum >= 16 )
            imageNum = 1;

            imageNum = parseInt(imageNum) + 1;
            img.src = "http:\\mysite\" + imageNum + ".png";
            }

            Use this javascript to your page inside <script> tag. :thumbsup:

            Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.


            My Latest Articles-->** Microsoft Bing MAP using Javascript
            CLR objects in SQL Server 2005
            Uncommon C# Keywords
            /xml>

            B N 2 Replies Last reply
            0
            • A Abhishek Sur

              A slight modification :

              var imageNum = 1;

              setInterval("changeImage()", 250);

              function changeImage()
              {
              if( imageNum >= 16 )
              imageNum = 1;

              imageNum = parseInt(imageNum) + 1;
              img.src = "http:\\mysite\" + imageNum + ".png";
              }

              Use this javascript to your page inside <script> tag. :thumbsup:

              Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.


              My Latest Articles-->** Microsoft Bing MAP using Javascript
              CLR objects in SQL Server 2005
              Uncommon C# Keywords
              /xml>

              B Offline
              B Offline
              bapu2889
              wrote on last edited by
              #6

              Thanks for your rep. but still I am not getting any ware as i dont know JS i copy and past between code but there are blue lines and i my assignment is asp.net using visual basic waiting for your kind rep. have a nice day

              N C 2 Replies Last reply
              0
              • A Abhishek Sur

                A slight modification :

                var imageNum = 1;

                setInterval("changeImage()", 250);

                function changeImage()
                {
                if( imageNum >= 16 )
                imageNum = 1;

                imageNum = parseInt(imageNum) + 1;
                img.src = "http:\\mysite\" + imageNum + ".png";
                }

                Use this javascript to your page inside <script> tag. :thumbsup:

                Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.


                My Latest Articles-->** Microsoft Bing MAP using Javascript
                CLR objects in SQL Server 2005
                Uncommon C# Keywords
                /xml>

                N Offline
                N Offline
                Not Active
                wrote on last edited by
                #7

                Abhishek Sur wrote:

                imageNum = parseInt(imageNum) + 1;

                Why? imageNum is already integer. Also, since imageNum is initialized as 1, parseInt(imageNum) + 1; would make it off by one.


                only two letters away from being an asset

                L A 2 Replies Last reply
                0
                • B bapu2889

                  Thanks for your rep. but still I am not getting any ware as i dont know JS i copy and past between code but there are blue lines and i my assignment is asp.net using visual basic waiting for your kind rep. have a nice day

                  N Offline
                  N Offline
                  Not Active
                  wrote on last edited by
                  #8

                  <html> <script> var imageNum = 1; setInterval(changeImage, 250); function changeImage() { if( imageNum >= 16 ) imageNum = 1; img.src = "http:\\mysite\" + imageNum + ".png"; } </script> <body> etc You have been given everything you need. Now, you really need to pick up a book and learn something about html and javascript on your own.


                  only two letters away from being an asset

                  1 Reply Last reply
                  0
                  • B bapu2889

                    Thanks for your rep. but still I am not getting any ware as i dont know JS i copy and past between code but there are blue lines and i my assignment is asp.net using visual basic waiting for your kind rep. have a nice day

                    C Offline
                    C Offline
                    Christian Graus
                    wrote on last edited by
                    #9

                    You have been given a copy and paste solution. If you still can't make it work, or understand it, that indicates your level of competence is too low to be able to use good help. Which is your problem. Buy a book and read it, then come back.

                    Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

                    N 1 Reply Last reply
                    0
                    • C Christian Graus

                      You have been given a copy and paste solution. If you still can't make it work, or understand it, that indicates your level of competence is too low to be able to use good help. Which is your problem. Buy a book and read it, then come back.

                      Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

                      N Offline
                      N Offline
                      Not Active
                      wrote on last edited by
                      #10

                      What's the expression? We can make it idiot proof, but they keep making better idiots. :rolleyes:


                      only two letters away from being an asset

                      1 Reply Last reply
                      0
                      • N Not Active

                        Abhishek Sur wrote:

                        imageNum = parseInt(imageNum) + 1;

                        Why? imageNum is already integer. Also, since imageNum is initialized as 1, parseInt(imageNum) + 1; would make it off by one.


                        only two letters away from being an asset

                        L Offline
                        L Offline
                        Lost User
                        wrote on last edited by
                        #11

                        Respect the Juniors. Even me i am wondering the type of girl I will marry. Many starters fear aspx client because of the many blue, red lines with many xml tags. Server side looks nice.

                        1 Reply Last reply
                        0
                        • N Not Active

                          Abhishek Sur wrote:

                          imageNum = parseInt(imageNum) + 1;

                          Why? imageNum is already integer. Also, since imageNum is initialized as 1, parseInt(imageNum) + 1; would make it off by one.


                          only two letters away from being an asset

                          A Offline
                          A Offline
                          Abhishek Sur
                          wrote on last edited by
                          #12

                          Well Mark, I agree, parseInt is not necessary.. I just used this for security purpose. But if you dont increment imageNum, how could it change the image? I think it should load 1.png, 2.png and so on... isnt it. :)

                          Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.


                          My Latest Articles-->** Microsoft Bing MAP using Javascript
                          CLR objects in SQL Server 2005
                          Uncommon C# Keywords
                          /xml>

                          N 1 Reply Last reply
                          0
                          • A Abhishek Sur

                            Well Mark, I agree, parseInt is not necessary.. I just used this for security purpose. But if you dont increment imageNum, how could it change the image? I think it should load 1.png, 2.png and so on... isnt it. :)

                            Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.


                            My Latest Articles-->** Microsoft Bing MAP using Javascript
                            CLR objects in SQL Server 2005
                            Uncommon C# Keywords
                            /xml>

                            N Offline
                            N Offline
                            Not Active
                            wrote on last edited by
                            #13

                            True, I forgot. My response has been edited. The increment should be after the imageNum is used.

                            Abhishek Sur wrote:

                            I just used this for security purpose.

                            Explain?


                            only two letters away from being an asset

                            A 1 Reply Last reply
                            0
                            • N Not Active

                              True, I forgot. My response has been edited. The increment should be after the imageNum is used.

                              Abhishek Sur wrote:

                              I just used this for security purpose.

                              Explain?


                              only two letters away from being an asset

                              A Offline
                              A Offline
                              Abhishek Sur
                              wrote on last edited by
                              #14

                              Mark Nischalke wrote:

                              Explain

                              Might be if somebody initializes it with "" .. or using some existing variable which is having value as character... (Not in this code ;) ):rose:

                              Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.


                              My Latest Articles-->** Microsoft Bing MAP using Javascript
                              CLR objects in SQL Server 2005
                              Uncommon C# Keywords
                              /xml>

                              1 Reply Last reply
                              0
                              Reply
                              • Reply as topic
                              Log in to reply
                              • Oldest to Newest
                              • Newest to Oldest
                              • Most Votes


                              • Login

                              • Don't have an account? Register

                              • Login or register to search.
                              • First post
                                Last post
                              0
                              • Categories
                              • Recent
                              • Tags
                              • Popular
                              • World
                              • Users
                              • Groups