Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ContentPlaceHolder and Javascript

Reply
Thread Tools

ContentPlaceHolder and Javascript

 
 
staeri@gmail.com
Guest
Posts: n/a
 
      07-21-2006
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?

 
Reply With Quote
 
 
 
 
=?Utf-8?B?Y2xpY2tvbg==?=
Guest
Posts: n/a
 
      07-21-2006
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.

"(E-Mail Removed)" 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?
>
>

 
Reply With Quote
 
 
 
 
Mark Rae
Guest
Posts: n/a
 
      07-21-2006
<(E-Mail Removed)> wrote in message
news:(E-Mail Removed) 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"


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
MasterPage and ContentPlaceHolder Path Paul ASP .Net 1 12-20-2007 07:18 PM
ContentPlaceHolder and overlaps PokerMan ASP .Net 1 03-19-2007 07:29 PM
MasterPage - ContentPlaceHolder - How to navigate to the ContentPlaceHolder "Child Page" Greg ASP .Net 4 04-17-2006 03:48 PM
Response.write and Contentplaceholder - Howto mosscliffe ASP .Net 8 04-07-2006 01:39 PM
MasterPage - ContentPlaceHolder - How to navigate to the ContentPlaceHolder "Child Page" Greg ASP .Net Web Controls 1 03-23-2006 10:17 AM



Advertisments