1

I am trying to get literal data from database to display news on homepage
whenever I change data in database I have to refresh whole page to see new data in div.
What I want to do is to click a button on homepage should reload/refesh data only for div.
the below script reloads the whole page

 <script>
    $("button3").click(function(){
        $("#container").load('WebForm1.aspx #container');

</script>

<form id="form1" runat="server">
    <div id="container">

<ul id="js-news" class="js-hidden" >
    <li class="news-item"><asp:Literal ID="news" runat="server" /></li>
    <li class="news-item"><asp:Literal ID="news1" runat="server" /></li>
    <li class="news-item"><asp:Literal ID="news2" runat="server" /></li>

</ul>
</div>        <asp:Button ID="Button3" runat="server" Text="Button" />

I hope you guys can help me out.Thanks I believe I need AJAX or something :/

Aakash Doshi
  • 202
  • 1
  • 3
  • 14

5 Answers5

0

Remove the runat Server attribute from your button, i think that should solve the problem

jonas vermeulen
  • 1,235
  • 5
  • 23
  • 40
0

You could put your data in a iframe and then use this iframe refresh method. More information on iframes here.

Community
  • 1
  • 1
BL1nK
  • 25
  • 3
0

You don't need server control to do that because it will do postback.. you can just use a HTML button

<input type="button" id="Button3" value="Button" />

another thing, if you need to reference server control in JavaScript like you doing you should use .ClientID()

  $("<%=Button3.ClientID %>")
Michael B.
  • 2,798
  • 1
  • 14
  • 18
0
$("button3").click(function(e){
        $("#container").load('WebForm1.aspx #container');
        e.preventDefault();
}

<asp:Button ID="Button3" runat="server" clientIdMode="static" Text="Button" />
Maverick
  • 478
  • 1
  • 3
  • 13
  • I added a video and played it.and then refreshed.but it refreshed video too.did not worked :( – Aakash Doshi Sep 01 '13 at 09:00
  • try running my code again, but remove this line: $("#container").load...... do look for error in firebug – Maverick Sep 01 '13 at 09:01
  • sorry did not get you. if I remove the line how will it know which DIV to refresh?? – Aakash Doshi Sep 01 '13 at 09:04
  • i just want to see, if that line is causing the issue. Bu default, a button tends to postback, no matter what you do. You can prevent postback, using preventdefault but if there are any js errors, then it postbacks automatically. – Maverick Sep 01 '13 at 09:07
  • I am using button with runat server so it will post back.If I remove it doesn't but it also does not pull new db data. – Aakash Doshi Sep 01 '13 at 09:16
  • This means the line i was asking you to remove has errors, probably the page path or something is not correct. – Maverick Sep 01 '13 at 09:18
0

Try this

<script>
    $("button3").click(function(){
        $("#container").load('WebForm1.aspx #container > *');
       });

</script>
SarathSprakash
  • 4,614
  • 2
  • 19
  • 35