>>>I have a asp page that includes a master page. I have placed a hidden input inside the content holder but it does not seem to be accessible via the java script.
>>>
>>><input type="hidden" id="rowindex" runat="server" />
>>>
>>>
>>>I do not get any errors when referencing this field in the code behind, but I can't seem to access it from java script. Also, when I view page source, it isn't there. Many others are that I don't have anything to do with, but mine is not there. Anybody know where I need to place this for it to be available?
>>>Thanks
>>>Tim
>>
>>Since you're including the "runat" ASP.NET is mangling the client name. The only reason you'd need it is if you want to access it from your code-behind page. Otherwise, remove it and it should appear as-is.
>
>Hi Paul,
>
>I do need to reference it from my code behind. I am setting the value in code behind, and then checking that value in java script. Is this true for input= as opposed to ASP HiddenField types? I tried both, but neither show up in my source. Interestingly in another sample page it works perfect but there isn't a master page involved and thus no Content holder.
>Tim
I have a duration label that I let the user set to days, weeks or months and save the display type they've chosen. I calculate the duration for each and set hidden variables server-side and then generate the javascript using the ClientID property so that it works correctly. Use Page.ClientScript to inject the JS into the page
private void SetDurationDisplayJS()
{
string js = @"
<script language = ""javascript"">
<!--
function SetDurationDisplay()
{
var label = document.getElementById('" + lblDuration.ClientID + "');"
+ @"
var selectedItem = $get('" + ddlDurationDisplay.ClientID + "').selectedIndex;"
+ @"
var display = $get('" + ddlDurationDisplay.ClientID + "').options[selectedItem].text;"
+ @"
if (display == 'Days')
{
label.innerText = $get('" + hdnDurationDays.ClientID + "').value;"
+ @"
}
else
{
if (display == 'Weeks')
{
label.innerText = $get('" + hdnDurationWeeks.ClientID + @"').value;
" + @"
}
else
if (display == 'Months')
{
label.innerText = $get('" + hdnDurationMonths.ClientID + @"').value;
" + @"
}
}
}
</script>";
if (!Page.ClientScript.IsClientScriptBlockRegistered("SetDurationDisplay"))
Page.ClientScript.RegisterClientScriptBlock(GetType(), "SetDurationDisplay", js);
ddlDurationDisplay.Attributes.Add("onchange", "javascript: SetDurationDisplay();");
}
Regards,
E.R. Gilmore