Results 1 to 5 of 5

Thread: How get contentplaceholder id using javascript

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2007
    Posts
    241

    Thumbs up How get contentplaceholder id using javascript

    Hi friends

    I need to get contentplaceholder id and assign to the variable. But i can't take

    contentplaceholder id using javascript. In alert message it gives null.This is my

    Code..

    function ShowContentOne()
    {
    var elemId=document.getElementById('<%=ContentPlaceHolder2.ClientId%>');

    elemId.style.display='block';
    elemId.style.visibility='visible';
    }

    I hope ur's reply.

    Thanks
    Failing to plan is Planning to fail

  2. #2
    Hyperactive Member syntaxeater's Avatar
    Join Date
    Dec 2006
    Location
    Des Moines, IA
    Posts
    460

    Re: How get contentplaceholder id using javascript

    Is ContentPlaceHolder2 an HTML element, an object on the serverside, a javascript prototype, or something else entirely?

    Could you also give us ore information (ie. how/when is this function being called)?

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jun 2007
    Posts
    241

    Thumbs up Re: How get contentplaceholder id using javascript

    Actually i am using master page and multiple content page. I have two link. Each link have one div. This links are placed in master page. One div1 is placed in content page 1 and another div2 is placed in content page2. While i give "set as start page" from mouse click while running, i click link2. But exception caught. That is div2 is "null". Because i am running content page1. So in the first content page what function and what control is available its working. But in content page 2 if i put function and some controls are available, it shows undefined or null. But i give set as start page to content page 2 its working.But content one is undefined( that is control and function ). This is my problem. I need to refresh the page.So i dynamically visible from content 1 to content 2. So i need to take contentplaceholder id. This is reference id of master page. That's all.

    I hope ur's reply.

    Thanks
    Failing to plan is Planning to fail

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: How get contentplaceholder id using javascript

    Is this related to your earlier thread? http://www.vbforums.com/showthread.php?t=541186

    Unfortunately your current question isn't very clear to me. You seem to want to do something between two pages but I can't tell what, so show us the code. All relevant code, not just the javascript you're trying to use.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jun 2007
    Posts
    241

    Re: How get contentplaceholder id using javascript

    frmMasterPage.Master:
    ==================
    <form id="form1" runat="server">

    <asp:ScriptManager ID="scriptManager1" runat="server">

    </asp:ScriptManager>
    <script type="text/javascript" language="javascript">

    function ShowContentTwo() //while set as start page is frmContentTwo.aspx
    {

    alert("from two content");
    this.id="frmMasterPage";
    alert(this.id);
    var elemId=document.getElementById('<%=form1.FindControl("ContentPlaceHolder2").ClientID%>');
    //var elemId=document.aspnetForm.frmMasterPage_ContentPlaceHolder2;
    alert(elemId);

    elemId.style.display='block';
    elemId.style.visibility='visible';

    alert("from master two");

    call()

    }

    </script>

    <div>
    <asp:UpdatePanel runat="server">
    <ContentTemplate>
    <a id="anchorLinkOne" runat="server" href="javascript:void(0)" onclick="ShowContentOne1()" style="color: blue; text-decoration: underline;cursorointer">Div One</a>
    </ContentTemplate>
    </asp:UpdatePanel>
    <br />
    <asp:UpdatePanel runat ="server" >
    <ContentTemplate>
    <a id="anchorLinkTwo" runat="server" href="javascript:void(0)" onclick="ShowContentTwo()" style="color: blue; text-decoration: underline;cursorointer">Div Two</a>
    </ContentTemplate>
    </asp:UpdatePanel>
    <br />

    </div>
    <div>
    <asp:contentplaceholder id="ContentPlaceHolder1" runat="server">
    </asp:contentplaceholder>
    <asp:ContentPlaceHolder ID ="ContentPlaceHolder2" runat="server">
    </asp:ContentPlaceHolder>
    </div>
    </form>

    frmContentPageOne.aspx :
    ===================
    <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <div id="divContentOne" runat="server" style="display:none;background-color:Red;height:500px;width:500px">

    </div>

    </asp:Content>

    frmContentTwo.aspx :
    =================
    <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder2" Runat="Server">

    <div id="divContentTwo" style="display:none;background-color:Green;height:500px;width:500px">

    </div>
    </asp:Content>
    Failing to plan is Planning to fail

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width