Solved

javascript object required, unknown name

Posted on 2009-05-08
19
913 Views
Last Modified: 2013-12-26
I've been asked to add a option in a dropdownlist in a form applikation. The dropdownlist is populated with other control types like textbox, textarea, radio, checkbox, and so on.. the dropdownlist has autopostback="true" and the selected control should trigger dynamically and be visible on the page, you can choose textbox 10 times for example.

My problem is: I have added the new control in the dropdownlist and replicated it like the others are built but now when the autopostback triggers i get these javascript errors: object required and unknown name, I don't have any code to show because it is at work, I'm hoping you can give me some advise on what may cause this.
0
Comment
Question by:mattegol
  • 10
  • 9
19 Comments
 
LVL 22

Expert Comment

by:prairiedog
ID: 24339116
Please delete the duplicate question first.
0
 

Author Comment

by:mattegol
ID: 24339217
deleted!
0
 
LVL 22

Expert Comment

by:prairiedog
ID: 24339256
Launch your app in FireFox, when the javascript error comes up, check the Error Console to see which line of code causes the error.
Without code, it is hard to debug.
0
 

Author Comment

by:mattegol
ID: 24339307
I tested it earlier in FireFox but no error was shown, the autopostback did not work though.
0
 
LVL 22

Expert Comment

by:prairiedog
ID: 24339337
Hmm, strange.
You will need to post some code so we can understand your problem better.
0
 

Author Comment

by:mattegol
ID: 24339555
This is Page_Load section
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
 

        '*********

        'first we check if the user is logged in. If not sent to LogIn page.

        'then we check that there is an eventid available. If not sent to register new event page.

        '****************

        Try

            If Session("Logged") = True Then

                'only proceed if event is not published

                If Session("EvPublished") <> "yes" Then
 
 

                    Dim strHeading As String

                    Dim lst As String = "" 'holds name of listbox to process

                    'strHeading = "Edit Reg Form"

                    'lblHeading.Text = strHeading
 

                    btnSave.Attributes.Add("onclick", "return ValErrorText();")
 

                    '******

                    'only show possibility of adding drop down options if that type of control is chosen

                    '******

                    dropoptions.Visible = False

                    radiooptions.Visible = False

                    regExpError.Visible = False

                    regExpMinMax.Visible = False

                    allocation.Visible = False

                    valrequired.Visible = True

                    reqErrorText.Visible = True

                    cctypelabel.Visible = False

                    ccNrLabel.Visible = False

                    ccDateLabel.Visible = False

                    ccCvcLabel.Visible = False

                    ccNrError.Visible = False

                    ccCVCError.Visible = False

                    chkShowCvC.Visible = False

                    txtarealabel.Visible = False

                    TextArea.Visible = False

                    help.Visible = True

                    frmlabel.Visible = True

                    frmEvalVal1Txt.visible = False

                    frmEvalVal2Txt.visible = False

                    frmEvalNrOptions.Visible = False

                        frmEvalQuestion.Visible = False

                        linkTextLabel.Visible = False

                        linkLabel.Visible = False
 
 

                    If Session("Eventid") > 0 Then
 

                        'check to see if a query string is coming in

                        'if so populate controls and put form in update mode

                        'this is fired from the dynamic edit buttons created on screen

                        If Not IsPostBack Then

                            If Request.QueryString.Count > 0 Then

                                Dim iControlid As Integer
 

                                iControlid = Request.QueryString("CID")
 

                                PopControls(iControlid)

                                ltlSaveFlag.Text = "Update"

                                ltlControlId.Text = iControlid

                                ddlControlType.Enabled = False
 

                            End If

                        End If
 

                        'build the preview at the bottom of page

                        BuildForm(Session("Eventid"), tdContainer, True, False)
 
 

                        If IsPostBack Then
 

                            Select Case ddlControlType.SelectedValue.ToUpper
 

                                Case "DROPDOWN"
 

                                    dropoptions.Visible = True
 

                                Case "RADIO"

                                    radiooptions.Visible = True

                                    valrequired.Visible = False

                                    reqErrorText.Visible = False
 

                                Case "CHECK"

                                    valrequired.Visible = False

                                    reqErrorText.Visible = False
 

                                Case "FIXED LENGTH", "MAX LENGTH"

                                    regExpError.Visible = True

                                    regExpMinMax.Visible = True
 

                                Case "NUMERIC"

                                    regExpError.Visible = True
 

                                Case "EMAIL"

                                    regExpError.Visible = True
 

                                Case "ALLOCATION"

                                    allocation.Visible = True

                                    regExpError.Visible = True

                                    valrequired.Visible = False

                                    reqErrorText.Visible = False
 

                                Case "SINGLEALLOCATION"

                                    allocation.Visible = True

                                    regExpError.Visible = True

                                    valrequired.Visible = False

                                    reqErrorText.Visible = False
 

                                Case "CREDITCARD"
 

                                    frmlabel.Visible = False

                                    cctypelabel.Visible = True

                                    ccNrLabel.Visible = True

                                    ccDateLabel.Visible = True

                                    ccCvcLabel.Visible = True

                                    ccNrError.Visible = True

                                    ccCVCError.Visible = True

                                    chkShowCvC.Visible = True
 

                                Case "SECTIONHEADER"

                                    valrequired.Visible = False

                                    reqErrorText.Visible = False

                                    help.Visible = False
 

                                Case "SUBSECTIONHEADER"

                                    valrequired.Visible = False

                                    reqErrorText.Visible = False

                                    help.Visible = False
 

                                Case "TEXTAREA"

                                    txtarealabel.Visible = True

                                    TextArea.Visible = True

                                    valrequired.Visible = False

                                    reqErrorText.Visible = False

                                    help.Visible = False

                                    frmlabel.Visible = False
 

                                Case "EVALUATION OPTIONS"

                                    radiooptions.Visible = False

                                    valrequired.Visible = False

                                    reqErrorText.Visible = False

                                    frmlabel.Visible = True

                                    frmEvalVal1Txt.Visible = True

                                    frmEvalVal2Txt.Visible = True

                                    frmEvalNrOptions.Visible = True

                                        frmEvalQuestion.Visible = True
 

                                    Case "LINK"

                                        'regExpError.Visible = True

                                        txtLinkText.Visible = True

                                        txtLink.Visible = True

                                        valrequired.Visible = False

                                        reqErrorText.Visible = False

                                        help.Visible = False

                                        frmlabel.Visible = False
 

                                End Select
 
 

                        End If

Open in new window

0
 

Author Comment

by:mattegol
ID: 24339661
controls
<tr>

		<td class="header" colSpan="2">Edit Form

		</td>

	</tr>

	<TR>

		<td colSpan="2"><IMG height="10" src="../../images/shim.gif"></td>

	</TR>

	<TR>

		<TD class="label" width="200"><asp:label id="Label1" runat="server">Choose Control Type:</asp:label></TD>

		<TD class="label" width="400"><asp:dropdownlist id="ddlControlType" runat="server" Width="300" AutoPostBack="True" CssClass="Companylist"></asp:dropdownlist></TD>

	</TR>

	<tr id="radiooptions" runat="server">

		<td class="label" vAlign="top" width="200"><asp:label id="Label7" runat="server">Enter Control Options:</asp:label></td>

		<td width="400"><asp:textbox id="txtradvalue1" runat="server"></asp:textbox>&nbsp;&nbsp;

			<asp:textbox id="txtradvalue2" runat="server"></asp:textbox></td>

	</tr>

	<tr id="dropoptions" runat="server">

		<td class="label" vAlign="top" width="200"><asp:label id="Label6" runat="server">Enter Control Options:</asp:label></td>

		<td width="400">

			<TABLE id="Table2" cellSpacing="1" cellPadding="1" width="400" border="0">

				<TR>

					<TD class="label" vAlign="top" width="270"><asp:textbox id="txtDropOption" runat="server"></asp:textbox>&nbsp;<A onclick="popListBox();" href="#"><IMG src="../../images/plus.gif" border="0"></A>

						&nbsp;<A onclick="DeleteListItem();" href="#"><IMG src="../../images/minus.gif" border="0"></A></TD>

					<TD class="label" width="170"><asp:listbox id="lstDropOption" runat="server" Width="170" CssClass="Companylist" SelectionMode="Multiple"></asp:listbox></TD>

				</TR>

			</TABLE>

		</td>

	</tr>

	<tr id="allocation" runat="server">

		<td>Enter Allocation Amt:</td>

		<td><asp:textbox id="txtAllocationAmt" runat="server" Width="50px"></asp:textbox></td>

	</tr>

	<TR id="regExpMinMax" runat="server">

		<TD class="label" vAlign="top" width="200">Enter Min/Max Value:</TD>

		<TD width="400"><asp:textbox id="txtMin" runat="server" Width="50px"></asp:textbox>&nbsp;

			<asp:textbox id="txtMax" runat="server" Width="50px"></asp:textbox></TD>

	</TR>

	<TR id="regExpError" runat="server">

		<TD class="label" vAlign="top" width="200">Enter Error Text.</TD>

		<TD width="400"><asp:textbox id="txtErrorText" runat="server" Width="300px" MaxLength="500"></asp:textbox></TD>

	</TR>

	<TR id="rptlabel" runat="server">

		<TD class="label" width="200"><asp:label id="Label5" runat="server">Enter Control Name:</asp:label></TD>

		<TD class="label" width="400"><asp:textbox id="txtCtlName" runat="server" Width="300" MaxLength="50"></asp:textbox></TD>

	</TR>

	<TR id="frmlabel" runat="server">

		<TD class="label" width="200"><asp:label id="Label2" runat="server">Enter Label Text:</asp:label></TD>

		<TD class="label" width="400"><asp:textbox id="txtControlLabel" runat="server" Width="300" MaxLength="500"></asp:textbox></TD>

	</TR>

	<!--Evaluation controls-->

	<TR id="frmEvalVal1Txt" runat="server">

		<TD class="label" width="200"><asp:label id="Label8" runat="server">Enter Left Text:</asp:label></TD>

		<TD class="label" width="400"><asp:textbox id="txtEvalVal1Txt" runat="server" Width="300" MaxLength="500"></asp:textbox></TD>

	</TR>

	<TR id="frmEvalVal2Txt" runat="server">

		<TD class="label" width="200"><asp:label id="Label9" runat="server">Enter Right Text:</asp:label></TD>

		<TD class="label" width="400"><asp:textbox id="txtEvalVal2Txt" runat="server" Width="300" MaxLength="500"></asp:textbox></TD>

	</TR>

	<TR id="frmEvalQuestion" runat="server">

		<TD class="label" width="200"><asp:label id="Label10" runat="server">Enter Question:</asp:label></TD>

		<TD class="label" width="400"><asp:textbox id="txtEvalQuestion" runat="server" Width="300" MaxLength="500"></asp:textbox></TD>

	</TR>

	<TR id="frmEvalNrOptions" runat="server">

		<TD class="label" vAlign="top" width="200">How many options?:(2-7):</TD>

		<TD width="400"><asp:textbox id="txtEvalOptions" runat="server" Width="50px"></asp:textbox></TD>

	</TR>

	<!--Credit Card Fields-->

	<tr id="cctypelabel" runat="server">

		<TD class="label" vAlign="top" width="200">Enter Type Label:</TD>

		<TD width="400"><asp:textbox id="txtCCtypeLabel" runat="server" Width="300px" MaxLength="500"></asp:textbox></TD>

	</tr>

	<tr id="ccNrLabel" runat="server">

		<TD class="label" vAlign="top" width="200">Enter Nr Label:</TD>

		<TD width="400"><asp:textbox id="txtCCnrLabel" runat="server" Width="300px" MaxLength="100"></asp:textbox></TD>

	</tr>

	<tr id="ccNrError" runat="server">

		<TD class="label" vAlign="top" width="200">Enter Nr Error:</TD>

		<TD width="400"><asp:textbox id="txtCCNrError" runat="server" Width="300px" MaxLength="100"></asp:textbox></TD>

	</tr>

	<tr id="ccDateLabel" runat="server">

		<TD class="label" vAlign="top" width="200">Enter Date Label:</TD>

		<TD width="400"><asp:textbox id="txtCCDateLabel" runat="server" Width="300px" MaxLength="100"></asp:textbox></TD>

	</tr>

	<tr id="chkShowCvC" runat="server">

		<TD class="label" vAlign="top" width="200">Show CVC?:</TD>

		<TD class="label" width="400"><asp:checkbox id="chkCVC" runat="server"></asp:checkbox></TD>

	</tr>

	<tr id="ccCvcLabel" runat="server">

		<TD class="label" vAlign="top" width="200">Enter CVC Label:</TD>

		<TD width="400"><asp:textbox id="txtCVCLabel" runat="server" Width="300px" MaxLength="100"></asp:textbox></TD>

	</tr>

	<tr id="ccCVCError" runat="server">

		<TD class="label" vAlign="top" width="200">Enter CVC Error:</TD>

		<TD width="400"><asp:textbox id="txtCCCvcError" runat="server" Width="300px" MaxLength="500"></asp:textbox></TD>

	</tr>

	<!--End of CreditCard Fields-->

	<!--Link Fields-->

	<tr id="linkTextLabel" runat="server">

		<TD class="label" vAlign="top" width="200">Link text:</TD>

		<TD width="400"><asp:textbox id="txtLinkText" runat="server" Width="300px" MaxLength="500"></asp:textbox></TD>

	</tr>

	<tr id="linkLabel" runat="server">

		<TD class="label" vAlign="top" width="200">Link:</TD>

		<TD width="400">

		    <asp:textbox id="txtLink" runat="server" Width="300px" MaxLength="500"></asp:textbox>

            <!--<asp:RegularExpressionValidator ID="RegularExpressionValidator1" ControlToValidate="txtLink" ValidationExpression="((https?|ftp|gopher|telnet|file|notes|ms-help):((//)|(\\\\))+[\w\d:#@%/;$()~_?\+-=\\\.&]*)" runat="server" ErrorMessage="Ange en giltig adress" />-->

		</TD>

	</tr>
 

	<!--End of Link Fields-->

	<TR id="valrequired" runat="server">

		<TD class="label" width="200"><asp:label id="Label3" runat="server">Is it Required:</asp:label></TD>

		<TD class="label" width="400"><asp:radiobutton id="rbYes" runat="server" GroupName="grpYesNo" Text="Yes"></asp:radiobutton><asp:radiobutton id="rbNo" runat="server" GroupName="grpYesNo" Text="No"></asp:radiobutton></TD>

	</TR>

	<TR id="reqErrorText" runat="server">

		<TD class="label" width="200"><asp:label id="lblRequiredText" runat="server">Required Error Text:</asp:label></TD>

		<TD class="label" width="400"><asp:textbox id="txtReqError" runat="server" Width="300" MaxLength="500"></asp:textbox></TD>

	</TR>

	<TR id="help" runat="server">

		<TD class="label" vAlign="top" width="200"><asp:label id="Label4" runat="server">Help Text:</asp:label></TD>

		<TD class="label" width="400"><asp:textbox id="txtHelpText" runat="server" Width="300" MaxLength="100" TextMode="MultiLine"></asp:textbox></TD>

	</TR>

	<tr id="txtarealabel" runat="server">

		<td class="label" colSpan="2"><asp:label id="lblTxtArea" Runat="server">Text:</asp:label></td>

	</tr>

	<tr id="TextArea" runat="server">

		<td class="label" colSpan="2"><asp:textbox id="txtTextArea" runat="server" Width="500" MaxLength="2000" TextMode="MultiLine"

				height="85"></asp:textbox></td>

	</tr>

	<TR>

		<td style="HEIGHT: 5px" colSpan="2"><IMG height="5" src="../../images/shim.gif">&nbsp;<INPUT id="lblList" type="hidden" runat="server"></td>

	</TR>

	<TR>

		<TD align="center" colSpan="2"><asp:button id="btnSave" runat="server" Text="Save"></asp:button>&nbsp;&nbsp;

			<asp:literal id="ltlSaveFlag" runat="server" Visible="False"></asp:literal><asp:literal id="ltlControlId" runat="server" Visible="False"></asp:literal></TD>

	</TR>

	<TR>

		<td colSpan="2"><IMG height="15" src="../../images/shim.gif">&nbsp;</td>

	</TR>

	<tr>

		<td class="header" colSpan="2">View Results

		</td>

	</tr>

	<TR>

		<td colSpan="2"><IMG height="10" src="../../images/shim.gif"></td>

	</TR>

</TABLE>

<table id="tblFormResult" cellSpacing="1" cellPadding="1" width="600" border="0">

	<tr>

		<td id="tdContainer" runat="server"></td>

	</tr>

</table>

Open in new window

0
 
LVL 22

Expert Comment

by:prairiedog
ID: 24339691
Strange, there is no JavaScript code in the code you provided. Do you have JavaScript code in ASPX file?
0
 

Author Comment

by:mattegol
ID: 24339783
the last code was from an user control

here is the aspx:
<%@ Register TagPrefix="uc1" TagName="ucMenu" Src="../EditControls/ucMenuEditEvent.ascx" %>

<%@ Register TagPrefix="uc1" TagName="ucEditForm" Src="../EditControls/ucEditForm.ascx" %>

<%@ Register TagPrefix="uc1" TagName="ucFooter" Src="../MainControls/ucFooter.ascx" %>

<%@ Register TagPrefix="uc1" TagName="ucHeader" Src="../MainControls/ucHeader.ascx" %>

<%@ Page Language="vb" AutoEventWireup="false" Inherits="RegisterForEvent.EditForm" CodeFile="EditForm.aspx.vb" %>

<HTML>

	<HEAD>

		<title>Edit Existing Event</title>

		<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">

		<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">

		<meta content="JavaScript" name="vs_defaultClientScript">

		<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">

		<LINK href="../../Styles.css" type="text/css" rel="stylesheet">

		<script language="javascript">

		

function popListBox(){
 

				var lBox=document.getElementById('ucEditForm:lstDropOption');

				var tBox = document.getElementById('ucEditForm:txtDropOption');

				var tValue = tBox.value

				var iIndex = lBox.options.length;

				if (tValue == "") {

				alert("You need to enter a value");

				}

				else

				lBox.options[iIndex]=new Option(tValue,iIndex+1);

				lBox.options[iIndex].value=tValue

				}

				

function popAllocationListBox(){
 

				var lBox=document.getElementById('ucEditForm:lstAllocation');

				var tAllBox = document.getElementById('ucEditForm:txtAllocationItem');

				var tAmtBox = document.getElementById('ucEditForm:txtAllocationAmt');

				var tAllValue = tAllBox.value

				var tAmtValue = tAmtBox.value

				

				

				var iIndex = lBox.options.length;

				if ((tAllValue == "")||(tAmtValue == "")) {

				alert("You need to enter an allocation Item and Amount");

				return false

				}

				else

				var lstValue = tAllBox.value + " " + "(" + tAmtBox.value + ")"

				lBox.options[iIndex]=new Option(lstValue,iIndex+1);

				lBox.options[iIndex].value=lstValue

				}

				

	function SelectAllItems(sList)

				{

		var el = document.getElementById(sList)

		var intCount=el.options.length;

		for(i = 0; i < intCount;i++)

		{

			el.options(i).selected=true;

		}

		}

		

	function DeleteListItem()

		{

				var lBox=document.getElementById('ucEditForm:lstDropOption');

				var iSelIndex =lBox.selectedIndex

				if(iSelIndex ==-1){

				alert("You need to selected an item to delete");

				return false

				}

				else

				lBox.remove(iSelIndex);

		}

		

function ValErrorText()

				{

				var op = document.getElementById("ucEditForm_rbYes")

				var tx = document.getElementById("ucEditForm_txtReqError")

					if(op.checked==true){
 

						if (tx.value.length < 1)

							{

							alert("You must add a validation error message.")

							return false;

							}

							else

							{

							

							return true;

							}

							}

				}

		</script>

	</HEAD>

	<body>

		<form id="Form1" method="post" onsubmit="SelectAllItems('ucEditForm:lstDropOption');"

			runat="server">

			<TABLE id="Table1" cellSpacing="1" cellPadding="1" width="760" border="0">

				<TR>

					<TD colSpan="2"><uc1:ucheader id="ucHeader" runat="server"></uc1:ucheader></TD>

				</TR>

				<TR>

					<td colSpan="2"><IMG height="5" src="../../images/shim.gif"></td>

				</TR>

				<TR>

					<TD vAlign="top" width="160"><uc1:ucmenu id="ucMenu" runat="server"></uc1:ucmenu></TD>

					<td width="500"><uc1:uceditform id="ucEditForm" runat="server"></uc1:uceditform></td>

				</TR>

				<TR>

					<td colSpan="2"><IMG height="200" src="../../images/shim.gif"></td>

				</TR>

				<TR>

					<TD colSpan="2"><uc1:ucfooter id="ucFooter" runat="server"></uc1:ucfooter></TD>

				</TR>

			</TABLE>

		</form>

	</body>

</HTML>

Open in new window

0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 22

Expert Comment

by:prairiedog
ID: 24339893
Line 93 is calling the JavaScript function by passing in 'ucEditForm:lstDropOption', but if 'ucEditForm:lstDropOption' is invisible, then when you do getElementById, you will get the JavaScript error as you mentioned in your question.
0
 

Author Comment

by:mattegol
ID: 24339952
So the controls can't be Visible="false" is that what you are saying?
0
 
LVL 22

Expert Comment

by:prairiedog
ID: 24339982
Yes, if Visible="False", then ASP.NET will not render it to browser, then JavaScript will not find it because it does not exist in the HTML. you can check it by viewing the Page Source in your browser.
0
 

Author Comment

by:mattegol
ID: 24340019
But it has been working fine before in .net 1.1. Is there a difference in the later versions?
0
 
LVL 22

Expert Comment

by:prairiedog
ID: 24340066
It should not be different. I don't know why it worked before but not working now. Mayber there are some changes in your application? Still launch your app in FireFox, then click Tools->Error Console to see the JavaScript error. Click the link of the error will show you which line is causing the JavaScript error.
0
 

Author Comment

by:mattegol
ID: 24340146
I made some of the controls visible and then it worked, but now I just have to figure out how many of them can be invisible..
0
 

Author Comment

by:mattegol
ID: 24340524
If I just set lstDropOption to visible all of the others work too, I just can't figure out why it worked before? Thanks, I'm almost there and i appreciate your help
0
 
LVL 22

Expert Comment

by:prairiedog
ID: 24340572
Yes, it is because there is only one place calls the JavaScript: Line 93, which is eventually looking for lstDropOption. It has nothing to do with other controls.
0
 
LVL 22

Accepted Solution

by:
prairiedog earned 500 total points
ID: 24340636
There is a trick for hiding the control. Instead of using Visible="False" to hide it, you can do this:
lstDropOption.Attributes.Add("style", "display:none;")
To make it visible again:
lstDropOption.Attributes.Add("style", "display:block;")
This way, ASP.NET will still render the control to browser, but the style will hide the cotnrol. Since it exists in HTML, it will not cause JavaScript error.
0
 

Author Closing Comment

by:mattegol
ID: 31579554
Thank you prairiedog
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now