Click here to Skip to main content
15,911,360 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
hi,

i face
C#
"Microsoft JScript runtime error: 'document.all.TextBox2' is null or not an object"
in following script

C#
<script language="javascript">
     function showDirectory() {
         document.all.TextBox2.value = window.showModalDialog("browseDirectory.aspx", 'jain', "dialogHeight: 560px; dialogWidth: 360px; edge: Raised; center: Yes; help: Yes; resizable: Yes; status: No;");

         return false;
     }
    
    </script>


in this form i use script manager, that is must for that page because of i use infragistic control.


how to solve this problem..

anybody help to me.
Posted
Updated 13-Nov-13 1:09am
v4

1 solution

document.all is a non-standard extension that even Microsoft removes it from IE.
So don't use it! Use document.getElementById('TextBox2'). It's standard and supported by every browser...

It became obvious - from comments - that the source of the HTML is an ASP.NET page.
ASP.NET creates it's own ids - based on what you entered - to ensure unique id fro page.
For details you may see INamingContainer[^].

It means that the id you give (TextBox2) is valid only for server-side. To access the very same object on client write your JavaScript like this

JavaScript
document.getElementById('<%=TextBox2.ClientID%>')
 
Share this answer
 
v2
Comments
sankmahesh 13-Nov-13 7:16am    
hi
i changed to
document.getElementById('TextBox2').value = window.showModalDialog("browseDirectory.aspx", 'jain', "dialogHeight: 560px; dialogWidth: 360px; edge: Raised; center: Yes; help: Yes; resizable: Yes; status: No;");

but error came again like this,
Line: 112
Error: 'document.getElementById(...)' is null or not an object
Kornfeld Eliyahu Peter 13-Nov-13 7:19am    
Can you show us the rest of your page, especially where TextBox2 declared?
sankmahesh 13-Nov-13 7:31am    
<%@ Page Title="" Language="C#" MasterPageFile="~/Main.Master" AutoEventWireup="true" CodeBehind="scheduler.aspx.cs" Inherits="SDMS.WebForm1" %>
<%@ Register assembly="Infragistics4.Web.v13.1, Version=13.1.20131.1012, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb" namespace="Infragistics.Web.UI.LayoutControls" tagprefix="ig" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<style type="text/css">
.style1
{
width: 100%;
}
</style>

<%-- <script language="javascript">
function showDirectory() {
document.all.TextBox2.value = window.showModalDialog("browseDirectory.aspx", 'jain', "dialogHeight: 560px; dialogWidth: 360px; edge: Raised; center: Yes; help: Yes; resizable: Yes; status: No;");

return false;
}

</script>--%>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

<script language="javascript">
function showDirectory() {
document.all.TextBox2.value = window.showModalDialog("browseDirectory.aspx", 'jain', "dialogHeight: 560px; dialogWidth: 360px; edge: Raised; center: Yes; help: Yes; resizable: Yes; status: No;");
// document.getElementById('TextBox2').value = window.showModalDialog("browseDirectory.aspx", 'jain', "dialogHeight: 560px; dialogWidth: 360px; edge: Raised; center: Yes; help: Yes; resizable: Yes; status: No;");
return false;
}

</script>
<div>
<div class="page_title">Scheduler</div>
<ig:WebTab ID="scheduler" runat="server" Height="200px" Width="500px">
<tabs>
<ig:ContentTabItem runat="server" Text="What">
<template>

<ig:ContentTabItem runat="server" Text="Finish">



</div>
Kornfeld Eliyahu Peter 13-Nov-13 7:38am    
There is no element named TextBox2 in this code. So it can not be found...
sankmahesh 13-Nov-13 7:41am    
<td>

<asp:TextBox ID="TextBox2" runat="server">
<asp:Button OnClientClick="showDirectory();" ID="Button4" runat="server" Text="Browse" />
</td>

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