Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Loading & changing image inside control

Reply
Thread Tools

Loading & changing image inside control

 
 
dbui
Guest
Posts: n/a
 
      03-03-2005
Hi,

I got a simple ascx. It has one image component. When first loaded, it scans
thru \images folder, loads the first image, and save the index & the string
array of picture names in session.

When user click on the Next button, it will increase the index by one and
reload the image according to this new index value.

I want this web-control to be able to refresh itself every 5 seconds. And it
could increase the index and load the image of this index in the array
names.

What is the best way in asp.net (not other scripts) to archieve this?

Thanks.


 
Reply With Quote
 
 
 
 
dbui
Guest
Posts: n/a
 
      03-03-2005
anybody please.


"dbui" <> wrote in message
news:...
> Hi,
>
> I got a simple ascx. It has one image component. When first loaded, it

scans
> thru \images folder, loads the first image, and save the index & the

string
> array of picture names in session.
>
> When user click on the Next button, it will increase the index by one and
> reload the image according to this new index value.
>
> I want this web-control to be able to refresh itself every 5 seconds. And

it
> could increase the index and load the image of this index in the array
> names.
>
> What is the best way in asp.net (not other scripts) to archieve this?
>
> Thanks.
>
>



 
Reply With Quote
 
 
 
 
Ken Cox [Microsoft MVP]
Guest
Posts: n/a
 
      03-04-2005
One way is to use some HTML in the page to cause the refresh and a Session
variable to track the index. I'm using a label for convenience here but
you'd want to pass Session("imageno") to your routine:


' This is the web user control
Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
If IsNothing(Session("imageno")) Then
Label1.Text = "Get the first image."
Else
Label1.Text = "Go get image # " & _
Session("imageno").ToString
End If
End Sub

' This is in the .aspx.vb code behind
Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Session("imageno") = Session("imageno") + 1
End Sub

Private Sub Button1_Click _
(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles Button1.Click
End Sub

This is the .aspx page

<%@ Register TagPrefix="uc1" TagName="imgfle" Src="imgfle.ascx" %>
<%@ Page Language="vb" AutoEventWireup="false"
Codebehind="countimage.aspx.vb" Inherits="p4320work.countimage"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head><meta http-equiv="refresh" content="600">
<title>countimage</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</head>
<body MS_POSITIONING="FlowLayout">
<form id="Form1" method="post" runat="server">
<p>
<uc1:imgfle id="Imgfle1" runat="server"></uc1:imgfle></p>
<p>
<asp:button id="Button1" runat="server"
Text="Next"></asp:button></p>
</form>
</body>
</html>


"dbui" <> wrote in message
news:...
> Hi,
>
> I got a simple ascx. It has one image component. When first loaded, it
> scans
> thru \images folder, loads the first image, and save the index & the
> string
> array of picture names in session.
>
> When user click on the Next button, it will increase the index by one and
> reload the image according to this new index value.
>
> I want this web-control to be able to refresh itself every 5 seconds. And
> it
> could increase the index and load the image of this index in the array
> names.
>
> What is the best way in asp.net (not other scripts) to archieve this?
>
> Thanks.
>
>


 
Reply With Quote
 
dbui
Guest
Posts: n/a
 
      03-04-2005
Thanks for the help KC. I just learned that meta-tag refreshing is
re-loading the page, not re-posting the page.

dbui


here is my final code 4 whoever may need
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If (IsNothing(Session("P"))) Then

Dim pics() As String =
Directory.GetFileSystemEntries(Server.MapPath("\im ages"), "*.jpg")

If pics.Length > 0 Then

Image1.ImageUrl = pics(0)

Session("P") = pics

Session("i") = 0

End If

Else

Dim pics() As String = Session("P")

Dim i As Integer = Session("i") + 1

If (i >= pics.Length) Then i = 0

Image1.ImageUrl = pics(i)

Session("i") = i

End If

End Sub




"Ken Cox [Microsoft MVP]" <> wrote in message
news:...
> One way is to use some HTML in the page to cause the refresh and a Session
> variable to track the index. I'm using a label for convenience here but
> you'd want to pass Session("imageno") to your routine:
>
>
> ' This is the web user control
> Private Sub Page_Load _
> (ByVal sender As System.Object, _
> ByVal e As System.EventArgs) Handles MyBase.Load
> If IsNothing(Session("imageno")) Then
> Label1.Text = "Get the first image."
> Else
> Label1.Text = "Go get image # " & _
> Session("imageno").ToString
> End If
> End Sub
>
> ' This is in the .aspx.vb code behind
> Private Sub Page_Load _
> (ByVal sender As System.Object, _
> ByVal e As System.EventArgs) Handles MyBase.Load
> Session("imageno") = Session("imageno") + 1
> End Sub
>
> Private Sub Button1_Click _
> (ByVal sender As System.Object, ByVal e As System.EventArgs) _
> Handles Button1.Click
> End Sub
>
> This is the .aspx page
>
> <%@ Register TagPrefix="uc1" TagName="imgfle" Src="imgfle.ascx" %>
> <%@ Page Language="vb" AutoEventWireup="false"
> Codebehind="countimage.aspx.vb" Inherits="p4320work.countimage"%>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
> <html>
> <head><meta http-equiv="refresh" content="600">
> <title>countimage</title>
> <meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
> <meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
> <meta name="vs_defaultClientScript" content="JavaScript">
> <meta name="vs_targetSchema"
> content="http://schemas.microsoft.com/intellisense/ie5">
> </head>
> <body MS_POSITIONING="FlowLayout">
> <form id="Form1" method="post" runat="server">
> <p>
> <uc1:imgfle id="Imgfle1" runat="server"></uc1:imgfle></p>
> <p>
> <asp:button id="Button1" runat="server"
> Text="Next"></asp:button></p>
> </form>
> </body>
> </html>
>
>
> "dbui" <> wrote in message
> news:...
> > Hi,
> >
> > I got a simple ascx. It has one image component. When first loaded, it
> > scans
> > thru \images folder, loads the first image, and save the index & the
> > string
> > array of picture names in session.
> >
> > When user click on the Next button, it will increase the index by one

and
> > reload the image according to this new index value.
> >
> > I want this web-control to be able to refresh itself every 5 seconds.

And
> > it
> > could increase the index and load the image of this index in the array
> > names.
> >
> > What is the best way in asp.net (not other scripts) to archieve this?
> >
> > Thanks.
> >
> >

>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
not declared error- control inside a control inside a webform DC Gringo ASP .Net 4 12-17-2007 02:22 AM
loading image -> detect when image is done loading edfialk Javascript 0 05-10-2007 07:28 PM
Loading Dynamic User Control Error: "The control must be placed inside a form tag with runat=server" Help Please Second time posting. davidr@sharpesoft.com ASP .Net 0 08-31-2006 05:26 PM
Access a control inside an usercontrol from another control inside another usercontrol nail ASP .Net 0 09-15-2004 03:55 PM
not declared error- control inside a control inside a webform DC Gringo ASP .Net Web Controls 3 09-14-2004 09:29 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57