By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,660 Members | 1,945 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,660 IT Pros & Developers. It's quick & easy.

javascript error: "Object required"

P: n/a
Hi,

This code gives an javascript error: "Object required" and never let see the
Alert window.
in code-behind:

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
Hiddenfield1.value="end text"
end sub

in aspx file:

<asp:HiddenField ID="hd1" runat="server" value="beginning
text"></asp:HiddenField>
<asp:Button ID="Button1" OnClientClick="test()" runat="server"/>

<script language="javascript" type="text/javascript">
function test()
{
var x = document.getElementById("hd1").value
alert(x)
}
</script>

Thanks
Phil
Mar 8 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Is the hd1 a part of any template or a content page or a user control? In
this case it will have a different id on the client. In any case you can
view the html source and check the actual id.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"Phil" <ph**@sgnomail.dkwrote in message
news:e7*************@TK2MSFTNGP04.phx.gbl...
Hi,

This code gives an javascript error: "Object required" and never let see
the Alert window.
in code-behind:

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
Hiddenfield1.value="end text"
end sub

in aspx file:

<asp:HiddenField ID="hd1" runat="server" value="beginning
text"></asp:HiddenField>
<asp:Button ID="Button1" OnClientClick="test()" runat="server"/>

<script language="javascript" type="text/javascript">
function test()
{
var x = document.getElementById("hd1").value
alert(x)
}
</script>

Thanks
Phil


Mar 8 '07 #2

P: n/a
"Phil" <ph**@sgnomail.dkwrote in message
news:e7*************@TK2MSFTNGP04.phx.gbl...
var x = document.getElementById("hd1").value
var x = document.getElementById("hd1").value
Mar 8 '07 #3

P: n/a
"Phil" <ph**@sgnomail.dkwrote in message
news:e7*************@TK2MSFTNGP04.phx.gbl...
var x = document.getElementById("hd1").value
var x = document.getElementById('<%=hd1.ClientID%>').value ;
Mar 8 '07 #4

P: n/a
Thank you guys, for replying.

"Mark Rae" <ma**@markNOSPAMrae.comschreef in bericht
news:Ol*************@TK2MSFTNGP04.phx.gbl...
"Phil" <ph**@sgnomail.dkwrote in message
news:e7*************@TK2MSFTNGP04.phx.gbl...
> var x = document.getElementById("hd1").value

var x = document.getElementById('<%=hd1.ClientID%>').value ;


Mar 8 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.