Hi All
Please help me with my code I keep getting an error as follow: Object reference not set to an instance of an object.
Here is whole code:
<SCRIPT Runat="Server">
Sub Page_Load
If Not Page.IsPostBack Then
'-- Load an array with image urls and save to View State
Dim ImageArray(3) As String
ImageArray(0) = "aspnet2.gif"
ImageArray(1) = "xhtml.gif"
ImageArray(2) = "jsdhtml.gif"
ViewState("PictureArray") = ImageArray
'-- Establish a counter to keep track of the array index
ViewState("Counter") = 0
MyImage.ImageURL = ImageArray(ViewState("Counter"))
Index.Text = ViewState("Counter")
End If
End Sub
Sub Get_Next_Image (Src As Object, Args As EventArgs)
'-- Retrieve the array from view state
Dim ImageArray() As String
ImageArray = ViewState("PictureArray")
'-- Increment the image counter
ViewState("Counter") += 1
If ViewState("Counter") > 2 Then
ViewState("Counter") = 0
End If
'-- Assign the next image to the control
MyImage.ImageURL = ImageArray(ViewState("Counter"))
Index.Text = ViewState("Counter")
End Sub
</SCRIPT>
<form Runat="Server">
<asp:Image id="MyImage" ImageAlign="AbsMiddle" Runat="Server"/>
<asp:Button Text="Next Image" OnClick="Get_Next_Image" Runat="Server"/>
<p>Array index: <asp:Label id="Index" Runat="Server"/></p>
</form>
Please help me with my code I keep getting an error as follow: Object reference not set to an instance of an object.
Here is whole code:
<SCRIPT Runat="Server">
Sub Page_Load
If Not Page.IsPostBack Then
'-- Load an array with image urls and save to View State
Dim ImageArray(3) As String
ImageArray(0) = "aspnet2.gif"
ImageArray(1) = "xhtml.gif"
ImageArray(2) = "jsdhtml.gif"
ViewState("PictureArray") = ImageArray
'-- Establish a counter to keep track of the array index
ViewState("Counter") = 0
MyImage.ImageURL = ImageArray(ViewState("Counter"))
Index.Text = ViewState("Counter")
End If
End Sub
Sub Get_Next_Image (Src As Object, Args As EventArgs)
'-- Retrieve the array from view state
Dim ImageArray() As String
ImageArray = ViewState("PictureArray")
'-- Increment the image counter
ViewState("Counter") += 1
If ViewState("Counter") > 2 Then
ViewState("Counter") = 0
End If
'-- Assign the next image to the control
MyImage.ImageURL = ImageArray(ViewState("Counter"))
Index.Text = ViewState("Counter")
End Sub
</SCRIPT>
<form Runat="Server">
<asp:Image id="MyImage" ImageAlign="AbsMiddle" Runat="Server"/>
<asp:Button Text="Next Image" OnClick="Get_Next_Image" Runat="Server"/>
<p>Array index: <asp:Label id="Index" Runat="Server"/></p>
</form>