To tell the truth,
the <asp:whatever controls are in the end rendered as normal html,
so you can always find out what kind of html tags the controls
produce
in the end and get innerText, innerHtml or value from them via
javascript
In any case, each control (included the hidden) will change id at
runtime:
the new id (that you need to get the element via Javascript) will be
composed with the id of each container and only at end with the id
you assigned to the control.
ie: look at id:
I added an hidden field to the <itemtemplate> of a Formview1
<asp:HiddenField ID="HidMyHidden" runat="server" Value="test" />
this is what I can read looking at the source of page that run in Ie:
<input type="hidden" name="FormView1$HidMyHidden"
id="FormView1_HidMyHidden" value="test" />
so to get this element via javascript I should know its "real id".
A way to do it is to compose the javascript function
(or the call to the javascript function to pass id of control as
parameter)
serverside, to be able to use NameOfControl.ClientId property, which
will
tell your script the real final Id of your hidden field
ie:
code behind of a page with a FormView1
where in the <ItemTemplate> I added
<asp:HiddenField ID="HidMyHidden" runat="server" Value="test" />
and with a normal Button (Button1) at bottom of page:
Imports System.Text
Partial Class frmReport
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
Dim sb As New StringBuilder()
sb.AppendLine("function alertTheId(trueHiddenId)")
sb.AppendLine("{")
sb.AppendLine(" var hidCtl=
document.getElementById(trueHiddenId);")
sb.AppendLine(" alert(trueHiddenId + ' value= ' +
hidCtl.value);")
sb.AppendLine(" return true;")
sb.AppendLine("}")
If Not
ClientScript.IsClientScriptBlockRegistered("TheTrueID") Then
ClientScript.RegisterClientScriptBlock(Me.GetType(),
"TheTrueID", sb.ToString(), True)
End If
'serverside you have the id you read in code
Dim hidCtl As HiddenField =
FormView1.FindControl("HidMyHidden")
Dim theclientId As String = ""
'be sure you get it, as I added it only in itemTemplate...
If Not hidCtl Is Nothing Then
theclientId = hidCtl.ClientID
Else
theclientId = "Not Found!!"
End If
Button1.OnClientClick = "javascript: return alertTheId('"
& theclientId & "')"
End If
End Sub