ClientScript.RegisterClientScriptBlock alerts gives Microsoft JScript runtime error

Last Reply on Dec 29, 2015 08:28 AM By Shashikant

Posted on Dec 29, 2015 05:51 AM

 

After ClientScript.RegisterClientScriptBlock  execution it gets  exception as 'Microsoft JScript runtime error: Unable to get value of the property 'options': object is null or undefined'.

 string mortgagorAddress = ds.Tables[0].Rows[0]["BMO_txtMortgagorAddress"].ToString();
            string BMONumber = ds.Tables[0].Rows[0]["BMO_txtBMONumber"].ToString();
            int duplicate = userBL.GetDuplicateInsertion(BMONumber,mortgagorAddress);
            if (duplicate >0)
            {
                ClientScript.RegisterClientScriptBlock(this.GetType(), "Duplicate", "alert('Duplicate Data Exists.');", true);
               return;
      

            }

Above given is my code.

Results 1 - 5 of 8 12
Posted on Dec 29, 2015 05:51 AM
Hi @josmijose100,
Please try the following

jQuery: Microsoft JScript runtime error: Object expected

It might help you.

Cheers Andrea.


Posted on Dec 29, 2015 06:02 AM

 

        function addOption(selectbox, text, value) {
            var optn = document.createElement("OPTION");
            text = text.replace(/&/g, '&');
            value = value.replace(/&/g, '&');                        
            optn.text = text;
            optn.value = value;
            selectbox.options.add(optn);
        }

        function fillstates() {           
            var stateArray = document.getElementById('hdnSateNames').value.split("#");
            for (var count = 0; count <= stateArray.length-2; count++) {
                var state = stateArray[count];               
                var stateCode = (state.split(";")[0]);
                var StateName = (state.split(";")[1]);
                addOption(document.getElementById('BMO_ddlMortgagorState'), StateName, stateCode);
            }
        }

        function fillAffiliates() {
            var AffiliateArray = document.getElementById('hdnAffiliates').value.split("#");
            for (var count = 0; count <= AffiliateArray.length - 2; count++) {
                var Affiliate = AffiliateArray[count];
                var AffiliateCode = (Affiliate.split("^")[0]);
                var AffiliateText = (Affiliate.split("^")[1]);

                addOption(document.getElementById('BMO_ddlAffiliate'), AffiliateText, AffiliateCode);
            }
        }

        function fillGroups() {
            var GroupArray = document.getElementById('hdnGroup').value.split("#");
            for (var count = 0; count <= GroupArray.length - 2; count++) {
                var Group = GroupArray[count];
                var GroupValue = (Group.split("^")[0]);
                var GroupText = (Group.split("^")[1]);
                addOption(document.getElementById('BMO_ddlBMOGroup'), GroupText, GroupValue);
            }
        }

in function  addOption() the line     

   selectbox.options.add(optn);

 get the error


Posted on Dec 29, 2015 06:09 AM
Andrea says:
Hi @josmijose100,
Please try the following

jQuery: Microsoft JScript runtime error: Object expected

It might help you.

Cheers Andrea.

 it doesnot help me.


Posted on Dec 29, 2015 06:23 AM

Hi,

Here I have created sample.Please check if your selectbox is undefined of null while passing to addOption Method.

HTML

<div>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
    <script type="text/javascript">
        $(function () {
            fillstates();
        });
        function addOption(selectbox, text, value) {
            var optn = document.createElement("OPTION");
            text = text.replace(/&amp;/g, '&');
            value = value.replace(/&amp;/g, '&');
            optn.text = text;
            optn.value = value;
            selectbox.options.add(optn);
        }

        function fillstates() {
            var stateArray = document.getElementById('<%=hdnSateNames.ClientID %>').value.split("#");
            for (var count = 0; count <= stateArray.length - 1; count++) {
                var state = stateArray[count];
                var stateCode = (state.split(";")[0]);
                var StateName = (state.split(";")[1]);
                addOption(document.getElementById('<%=BMO_ddlMortgagorState.ClientID%>'), StateName, stateCode);
            }
        }
    </script>
        
    <asp:HiddenField ID="hdnSateNames" Value="01;Maharashtra#02;Goa" runat="server" />
    <asp:DropDownList ID="BMO_ddlMortgagorState" runat="server">
    </asp:DropDownList>
</div>

Screenshot