开发者

Stopping twitter api from refreshing

开发者 https://www.devze.com 2023-03-20 02:26 出处:网络
On my webpage, I have the following link: <asp:LinkButton ID=\"lnkChangePic\" runat=\"server\" onclick=\"lnkChangePic_Click\" Text=\"Upload new profile picture\"></asp:LinkButton>

On my webpage, I have the following link:

<asp:LinkButton ID="lnkChangePic" runat="server" onclick="lnkChangePic_Click" Text="Upload new profile picture"></asp:LinkButton>

When you click it, it calls this function:

    protected void lnkChangePic_Click(object sender, EventArgs e)
{
    pnlUpload.Visible = true;
    pnlChangePic.Visible = false;
}

The link is present in pnlChangePic. pnlUpload is initially not visible. I want the page to be as responsive as possible when the user clicks this link, and at the moment, when the user clicks, only two bits of the page change: the panels, and a twitter stream that is also on the page:

        <div class="fr">   

            <h4 id="twitter">Twitter Stream</h4>
            <script src="http://widgets.twimg.com/j/2/widget.js"></script>
            <script>
                new TWTR.Widget({
                    version: 2,
                    type: 'profile',
                    rpp: 4,
                    interval: 6000,
                    width: 430,
                    height: 300,
                    theme: {
                        shell: {
                            background: '#000',
                            color: '#666'
                        },
                        tweets: {
                            background: '#000',
                            color: '#666',
                            links: '#ffa20f'
                        }
                    },
                    features: {
                        scrollbar: false,
                        loop: false,
       开发者_StackOverflow中文版                 live: false,
                        hashtags: true,
                        timestamp: true,
                        avatars: false,
                        behavior: 'all'
                    }
                }).render().setUser(asdf').start();
            </script> 
        </div>

What should I do to make it so the twitter steam does not refresh when the user clicks the link? I can can get it to stop doing that, the page will be much more responsive.


You want to run some server-side code without reloading the entire page.

You have two main options -

  • put the section that you do want to update in an UpdatePanel and update it with ASP.Net AJAX(clicking on a button within an UpdatePanel will trigger an Async Postback - only the part of the page within the UpdatePanel will be updated)

  • cache the output of the Twitter control and serve the cached version on postback. As the Twitter control seems to be entirely client-side this would probably be a little difficult.

Your best bet is probably the ASP.Net AJAX UpdatePanel.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号