0

I am having a div. I am passing a HTML string to that div using INNERHTML in JSON. The div is not coming in the output.

Here is my code

$('#<%=btnSubmitData.ClientID %>').live('click', function () {
     var jsonParameters = '{"startProductLevelId":"' + prdLvlId1 + '"}';
       $.ajax({
            type: "POST",
            url: "../Test/Test.aspx/PopulateData",
            context: this,
            cache: false,
            data: jsonParameters,
            contentType: 'application/json',
            dataType: "json",
            "success": function (LastweeksData) {
             $("#brandData").css("display", "block");
             alert(LastweeksData.d); //Here i am getting the value
             document.getElementById('<%=brandData.ClientID%>').innerHTML = LastweeksData.d;
             },
             "error": function (request, status, error) {
              alert(error);
             }
          })
        });

My div - "brandData"

  <asp:UpdatePanel ID="UpdatePanel2" runat="server">
    <ContentTemplate>
     <div id="dummy1" style="width: 100%; height: 20px; float: left">
     </div>
     <div id="Div2" style="width: 100%; height: 20px; float: right; border-style: solid; border-width: 0px;">
       <table id="Table1" align="center" cellspacing="0" border="0" cellpadding="0" width="950">
         <tr>
             <td width="500" align="left" valign="top">
                  <div id="brandData" runat="server">
                   </div>
             </td>
         </tr>
       </table>
   </div>

I had also tried like this.

$("#brandData").innerHTML = LastweeksData.d;

I cant able the see the div in the output. I dont know where i am wrong.

1
  • the alert inside the success callback is firing? Commented Nov 9, 2013 at 17:29

2 Answers 2

0

$("#brandData").innerHTML will not work as $("#brandData") returns a jQuery object not a dom element reference so it does not have the innerHTML property.

You can use .html() utility method provided by jQuery to set the html content of an element.

Try

$("#brandData").html(LastweeksData.d)
Sign up to request clarification or add additional context in comments.

1 Comment

i had tried like this "$("#brandData").html(LastweeksData.d);" but still i am facing the same problem.
0

You have runat="server" to the id brandData, so you cannot use $("#brandData") as a selector since the ID gets changed when it renders in the DOM with the prepended master and page information.(ex: master_page_ctl100_brandData)

<div id="brandData" runat="server">

Instead use $('[id$=brandData]') or $('#<%=brandData.ClientID %>') as your selector. There are few other options too.

A comprehensive list on how to target asp.net controls in jquery are listed here

3 Comments

@RobinHood use $('[id$=brandData]').html()
I had tried like this "$('[id$=brandData]').innerHTML = LastweeksData.d;" and also tried '$('[id$=brandData]').html = LastweeksData.d;' and also "$('[id$=brandData]').html() = LastweeksData.d;"....Nothing seems to be working....
try this $('[id$=brandData]').html(LastweeksData.d)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.