473,405 Members | 2,415 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

ContentPlaceHolder and Javascript

I want to catch the value in "hidID" when the form on the page is
posted but I get an error message telling me "Object is required".

<asp:Content ID="Content1"
ContentPlaceHolderID="ContentPlaceHolderLeft" runat="server">

<script language="javascript">
var a1 = document.getElementById("hidID").value; -- THIS GIVES
ERROR MESSAGE --

function RadioClick(id)
{
a1 = id;
document.getElementById("hidID").value = a1;

if ( a1 == "p1")
{
document.getElementById("p1").style.display = "block";
document.getElementById("p2").style.display = "none";
}
else
{
document.getElementById("p1").style.display = "none";
document.getElementById("p2").style.display = "block";
}
}
</script>

Can someone please help me?

Jul 21 '06 #1
2 8127
What is hidID, if it is an ASP.net control then it's client side ID for use
in JavaScript is different to the ID you give it in ASP.net markup/code. The
Id the control will have cleint side is stored in the ClientID proeprty of
the control. You shouldn't hard code the ID of the control in your
Javascript, instead dynamically create the javascript server side and use the
clientID property of the control. This way if you make changes to the code
that would affect the client side ID of the control it will not break your
javascript.

"st****@gmail.com" wrote:
I want to catch the value in "hidID" when the form on the page is
posted but I get an error message telling me "Object is required".

<asp:Content ID="Content1"
ContentPlaceHolderID="ContentPlaceHolderLeft" runat="server">

<script language="javascript">
var a1 = document.getElementById("hidID").value; -- THIS GIVES
ERROR MESSAGE --

function RadioClick(id)
{
a1 = id;
document.getElementById("hidID").value = a1;

if ( a1 == "p1")
{
document.getElementById("p1").style.display = "block";
document.getElementById("p2").style.display = "none";
}
else
{
document.getElementById("p1").style.display = "none";
document.getElementById("p2").style.display = "block";
}
}
</script>

Can someone please help me?

Jul 21 '06 #2
<st****@gmail.comwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
>I want to catch the value in "hidID" when the form on the page is
posted but I get an error message telling me "Object is required".

<asp:Content ID="Content1"
ContentPlaceHolderID="ContentPlaceHolderLeft" runat="server">

<script language="javascript">
var a1 = document.getElementById("hidID").value; -- THIS GIVES
ERROR MESSAGE --
Once your page has loaded, do a View Source and search for hidID - you'll
see that the MasterPage / Content Page architecture has renamed it.

So, you need add the following to your MasterPage's code:

protected void Page_Init(object sender, EventArgs e)
{
this.ID = "MyMasterPage"; // or whatever name you prefer
}

Now, you can refer to your controls client-side as follows:

var a1 =
document.aspnetForm.MyMasterPage_ContentPlaceHolde rLeft_hidID.value;

or

var a1 =
document.getElementById("MyMasterPage_ContentPlace HolderLeft_hidID").value;

N.B. no matter what you name your form, the MasterPage / ContentPage
architecture always renames it to "aspnetForm" :-)
Jul 21 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Billy Cormic | last post by:
Hello, I am using Visual Studio 2005 Beta for the first time and am having trouble using contentplaceholders. Actually, I am having trouble declaring them. Here is a snap shot of my master page:...
8
by: mosscliffe | last post by:
I am an old programmer, but a newbie to Visual Web Developer 2005 - Express Edition I have an .aspx Form Page with an attached Master File and an attached css file. I have scanned a text...
0
by: nickster | last post by:
For some reason when I use asp controls for the default content of a ContentPlaceHolder, they do not get rendered. Static content is rendered just fine however! Specifically I'm using multiple...
2
by: Andrew Robinson | last post by:
I would like to use a ContentPlaceHolder within the following. Any ideas on how to best accomplish this? <td rowspan="2" style="width: 600px; background-image: url('<asp:ContentPlaceHolder...
3
by: =?Utf-8?B?TmFuY3lB?= | last post by:
Hi - We need to be able to invoke a child (contentplaceholder) page from a master page and have the child run some jscript code in the initialization event to load data specific to that child. We...
2
by: premchandrasingh | last post by:
Hi I am using a master page in which I have only one contentplaceholder and inside this contentplaceholder I added a label. The problem is when I tried to assign some value to this label from...
3
by: jobs | last post by:
Hello. I have a master page with ContentPlaceHolder under a html Div tag. That DIV tag has CSS that positions it. While in Visual Studio design view, that div tag and contentplace holder does...
1
by: =?Utf-8?B?ampmbGFzaA==?= | last post by:
I have a master page with a contentplaceholder object. When creating content pages, I'm adding controls to the contentplaceholder area. The contentplaceholder is not stretching so that I can...
1
by: mil111 | last post by:
Hi, Can anybody help me? I created master page (in table) with header, footer, left column and in the right column is contentPlaceHolder. Content on contentPlaceHolder is longer than the left...
0
by: Andy B | last post by:
I have a div on the master page that is 600px high. It has a left pannel, main content (contentPlaceHolder) inside another div and a footer. What I am looking for is a few things: 1. How do you...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.