Kannan
Kannan

Reputation: 829

Microsoft JScript runtime error: Object expected thrown when called from codebehind

I am using jquery ui tabs and tooltip and it works perfectly.Heres the code for jquery-ui tabs

$(function() {
  $( "#tabs" ).tabs();
  $(document).tooltip(); 
});   

I wrote another function which i want to call from code behind on button click event

function setDiv(type){
    alert(type);         
}

Heres my codebehind function.

protected void btnNext_Click(object sender, EventArgs e)
{
    pnlResult.Visible=True;
    ScriptManager.RegisterClientScriptBlock(Page, typeof(Page), "script type='text/javascript' language='javascript'",
    "setDiv('highlight')();", true);
}

The problem is when i click the btnNext button ,alert saying highlight is showing.After that i am getting the object expected error on the aspx page and the error points on

<div id="tabs-1">(div used for creating tabs)

Here's my aspx page

<div id="tabs">
    <ul>
        <li><a href="#tabs-1">Nunc tincidunt</a></li>
        <li><a href="#tabs-2">Proin dolor</a></li>
        <li><a href="#tabs-3">Aenean lacinia</a></li>
    </ul>
<div id="tabs-1">//Here's where i am getting the error
    <p>
        <asp:Panel ID="pnlResult" runat="server" Visible="false">
            <div id="divResult"  runat="server">
                <span id="spIcon"   style="float:left;margin-left:3px;"></span>
                Successfully inserted
            </div>
        </asp:Panel>
        <table style="width:50%" id="tbl" runat="server" >
            <tr>
                <td>
                   Your Name:
                </td>
                <td>
                    <input id="name" title="Enter your name here" />
                </td>
            </tr>
            <tr>
                <td >
                    <span class="ui-icon ui-icon-alert"  style="float:left;margin-left:3px;"></span>
                    <input type="button" id="btnSubmit" value="Submit" />
                </td>
            </tr>
        </table>
    </p>
</div>
<div id="tabs-2">
    <p>Tab2.</p>
</div>
<div id="tabs-3">
    <p>Tab3.</p>
    <p>Tab is placed.</p>
</div>
</div>

Upvotes: 2

Views: 1484

Answers (1)

Mathew Thompson
Mathew Thompson

Reputation: 56429

Your script that you are building in your code behind is malformed, try this:

ScriptManager.RegisterClientScriptBlock(
    Page, 
    typeof(Page), 
    "setDiv",
    "<script type='text/javascript'>setDiv('highlight');</script>",
     false);

Upvotes: 1

Related Questions