I have a Page which contains the image control which displays the images from Specific Folder (Slide Show) using Javascript. I have set the value of HiddenField Value on Page Load and want to access these values using Javascript. But, after setting the value of Hidden Field on Page Load the value of Hidden Field in Javascript shows NULL.
In .aspx page:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="Scripts/jquery-1.4.1.min.js"></script>
</head>
<script type="text/javascript">
var folderNm = document.getElementById('<%#HiddenFieldFolderName.ClientID%>');
var MaxIndex = document.getElementById('<%#HiddenFieldMaxIndex.ClientID%>');
var mainImage = document.getElementById('mainImage');
//mainImage.src = "Presentations/7/Slide1.GIF";
//Initilize start value to 1 'For Slide1.GIF'
var currentIndex = 1;
//NOTE: Set this value to the number of slides you have in the presentation.
//var maxIndex = 7;
var maxIndex = MaxIndex;
alert("Folder Name " + folderNm + "\n MaxIndex " + MaxIndex);
function swapImage(imageIndex) {
//Check if we are at the last image already, return if we are.
if (imageIndex > maxIndex) {
currentIndex = maxIndex;
return;
}
//Check if we are at the first image already, return if we are.
if (imageIndex < 1) {
currentIndex = 1;
return;
}
currentIndex = imageIndex;
//Otherwise update mainImage
//document.getElementById("mainImage").src = 'PPT/GIFs/Slide' + currentIndex + '.GIF';
document.getElementById("mainImage").src = 'Presentations/' + folderNm + '/' + 'Slide' + currentIndex + '.GIF';
// document.getElementById("mainImage").src = 'Presentations/7/Slide' + currentIndex + '.GIF';
return;
}
</script>
<body>
<form id="form1" runat="server" >
<div>
<div>
<%-- <img src="PPT/GIFs/Slide1.GIF" id="mainImage" name="mainImage" width="50%" height="50%" alt="">--%>
<img id="mainImage" name="mainImage" width="25%" height="25%" alt="">
</div>
<div>
<a href="#" onclick="swapImage(0);">
<img src="/images/firstss.png" border="0" alt="First"></a>
<a href="#" onclick="swapImage(currentIndex-1);">
<img src="/images/prev.png" border="0" alt="Previous"></a>
<a href="#" onclick="swapImage(currentIndex+1);">
<img src="/images/nexts.png" border="0" alt="Next"></a>
<a href="#" onclick="swapImage(maxIndex);">
<img src="/images/lasts.png" border="0" alt="Last"></a>
</div>
<div>
<asp:HiddenField ID="HiddenFieldMaxIndex" runat="server" />
<asp:HiddenField ID="HiddenFieldFolderName" runat="server" />
</div>
</div>
</form>
</body>
</html>
In .aspx.cs file:
protected void Page_Load(object sender, EventArgs e)
{
string foldername = string.Empty;
if (Request.QueryString["di"] != null)
{
foldername = Request.QueryString["di"].ToString();
HiddenFieldFolderName.Value = foldername;
HiddenFieldMaxIndex.Value = Request.QueryString["Files"].ToString();
}
}
Here, the Hidden Field value shows null in alert() box. Help Appreciated.