Javascriptを使用して特定のフォルダー(スライドショー)から画像を表示する画像コントロールを含むページがあります。ページ読み込み時に HiddenField Value の値を設定しましたが、Javascript を使用してこれらの値にアクセスしたいと考えています。ただし、ページの読み込み時に隠しフィールドの値を設定した後、Javascript の隠しフィールドの値は NULL を示します。
.aspx ページ:
<!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>
.aspx.cs ファイル内:
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();
}
}
ここで、非表示フィールドの値は、alert() ボックスで null を示しています。助けてください。