Click here to Skip to main content
16,017,944 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
function pnlvisible()
        {
            //document.getElementById('ctl00_ContentPlaceHolder1_drptree_pnl').
            //if (document.getElementById("ctl00_ContentPlaceHolder1_drptree_pnl").style.visibility == "visible")
            //{
                document.getElementById("ctl00_ContentPlaceHolder1_drptree_pnl").style.visibility = 'hidden';
            //}

    }





i am getting Microsoft JScript runtime error: Object required during the runtime.
what is error .Is there anyway to solve this.
Posted

1 solution

Error for the above line means that the following was undefined: document.getElementById("ctl00_ContentPlaceHolder1_drptree_pnl"). Thus, when you try to access certain property, it is unable to find the object and thus raises an error.

2 Options:
1. Either make sure that the name is exactly the same as when page rendered (you can get it doing page view source)
2. Use: <%= myPanel.ClientID %>
 
Share this answer
 
v2
Comments
Member 9364222 25-Sep-12 8:40am    
function ShowPanel()
{
if (event.keyCode == 13)
{
document.getElementById("pnl1").style.Visibility = 'visible';
}
}


my aspx control is
<asp:TextBox ID="txtare" runat="server" class="Txt-box1" Width="230px"/>
<asp:Panel ID="pnl1" runat="server" BorderColor="Black" BorderWidth="1px" Width="250px"
Style="position: absolute; background-color: White; visibility: hidden" Height="250"
ScrollBars="Auto" ClientIDMode="Static">
<div id="trvdiv" runat="server">
<asp:TreeView ID="trev" runat="server" Width="100%" CssClass="myTxt" ImageSet="Msdn"
NodeIndent="10" ShowLines="True" NodeWrap="True" OnSelectedNodeChanged="trev_SelectedNodeChanged">
<ParentNodeStyle Font-Bold="True" HorizontalPadding="5px" />
<hovernodestyle font-underline="True">
<SelectedNodeStyle Font-Underline="False" HorizontalPadding="3px" VerticalPadding="1px" />
<nodestyle font-names="Verdana" font-size="8pt" width="100%" forecolor="Black" horizontalpadding="5px"
="" nodespacing="1px" verticalpadding="2px">
<rootnodestyle horizontalpadding="5px" width="100%" font-bold="True" forecolor="#0E5D7A">
<leafnodestyle horizontalpadding="5px" width="100%">

</div>


In my aspx.cs i have included

txtare.Attributes.Add("onkeypress", "ShowPanel()");




While running i am getting the microsoft jscript runtime error:Object required

Is there any solution for this.
Sandeep Mewara 25-Sep-12 10:00am    
Depends on what line the error is occurring!
Member 9364222 26-Sep-12 2:57am    
document.getElementById("pnl1").style.Visibility = 'visible';

I am getting the error on this line
Sandeep Mewara 26-Sep-12 3:03am    
This just means that the object document.getElementById("pnl1"). was null and not found OR document.getElementById("pnl1").style.Visibility was null.
I see you used a capital V for visibility. It should be small. Try:
document.getElementById("pnl1").style.visibility and try.

P.S.:
If you set a controls visiblity as false in the code behind(server side) during page load, that control will not render and thus any reference to it on client side cannot be made.

If you want to play with visibility of such controls, use 'display' property in such scenarios.

Do: document.getElementById("pnl1").style.display = 'block';
Use atrributes.Add to set display as hidden in code behind.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900