Solved

Postback causes Javascipted button to disappear

Posted on 2010-11-08
2
988 Views
Last Modified: 2012-05-10
Hello, I have a webuser control on a page that resides in an update panel. In this control I have two calendar controls that have their autopostback = true, so I can capture the selected date and perform some functions.

My control searches a database for blog posts for the timespan of the two calendar controls. Once the results are displayed in my gridview control, I have a facebook share button so users can share the blog post on their facebook wall.

This all works perfectly if the dates are manually set and the calendar controls are not used. If the calendar controls are used the facebook share button disappears.

Attached is my control. How can I over come this issue???

Sorry for the long code example. The facebook link and javascript is near the bottom.
<%@ Control Language="VB" AutoEventWireup="false" CodeFile="SearchPostIt.ascx.vb"
    Inherits="Controls_Site_SearchPostIt" %>
<%@ Register TagPrefix="obout" Namespace="OboutInc.Calendar2" Assembly="obout_Calendar2_Net" %>
<%@ Register TagPrefix="obout" Namespace="OboutInc.Editor" Assembly="obout_Editor" %>

   <asp:ScriptManager runat="server" ID="scriptmgr">
                </asp:ScriptManager>
                <asp:UpdatePanel ID="upJoin" runat="server">
                    <ContentTemplate>
<h4 class="heading colr">
    Search Post It!</h4>
<div id="search_PostItControls">
    Start Date&nbsp;
    <obout:Calendar runat="server" ID="calStartDate" DatePickerImagePath="~/Controls/Calendar_data/icon2.gif"
        DatePickerMode="true" StyleFolder="~/Controls/Calendar_data/blue/" TextBoxId="txtStart"
        DatePickerSynchronize="true" DateMin="2000-01-01" AutoPostBack="true">
    </obout:Calendar>
    <strong>
        <asp:Label runat="server" ID="lblStartDate"></asp:Label></strong> End Date&nbsp;
    <obout:Calendar runat="server" ID="calEndDate" DatePickerImagePath="~/Controls/Calendar_data/icon2.gif"
        DatePickerMode="true" StyleFolder="~/Controls/Calendar_data/blue/" TextBoxId="txtEnd"
        DatePickerSynchronize="true" DateMin="2000-01-01"  AutoPostBack="true">
    </obout:Calendar>
    &nbsp;&nbsp;&nbsp; <strong>
        <asp:Label runat="server" ID="lblEndDate"></asp:Label></strong>&nbsp;&nbsp;&nbsp;
    <asp:LinkButton runat="server" ID="ibtnSearch" Text="Search Posts" TabIndex="1" class="simplebtn"></asp:LinkButton>
</div>
<div class="clear">
</div>
<asp:LinkButton runat="server" ID="lbRecentPosts" Text="Recent Posts" PostBackUrl="~/Default.aspx"
    Font-Underline="true"></asp:LinkButton>
<asp:GridView runat="server" ID="gvPostIts" AutoGenerateColumns="false" GridLines="None">
    <Columns>
        <asp:TemplateField>
            <ItemTemplate>
                <div id="PostIt">
                    <div id="PostIt_Left">
                        <a style="text-decoration: underline; font-weight: bold" rel="shadowbox;options{dimensions:height=800;width=790}"
                            id="lbMemberLink" href='<%# "Member.aspx?UserId=" & eval("UserId") %>'>
                            <img src="<%#"Images/Members/Profile/" & Eval("smPhoto") %>" alt="<%# Eval("Fullname") %>"
                                style="border: none" />
                        </a>
                    </div>
                    <div id="PostIt_Right">
                        <div class="postIt_Title">
                            <h6>
                                <%# Eval("Fullname") %></h6>
                            <span class="postIt_Date">
                                <%# Eval("Created") %></span> <span class="postIt_Delete">
                                    <asp:LinkButton runat="server" ID="lbDeletePostIt" Text="X" CommandName="Select"
                                        class="simplebtn" OnClick="lbDeletePostIt_Click"></asp:LinkButton>
                                </span>
                        </div>
                        <div class="clear">
                        </div>
                        <div class="postIt_Comment">
                            <%# Eval("Comment") %>
                        </div>
                        <asp:Label ID="lblPostItId" runat="server" Text='<%# Eval("PostItId") %>' Visible="false" />
                    </div>
                    <div class="clear">
                    </div>
                    <asp:GridView runat="server" ID="gvComments" AutoGenerateColumns="false" GridLines="None"
                        OnRowDataBound="gvComments_RowDataBound">
                        <Columns>
                            <asp:TemplateField>
                                <ItemTemplate>
                                    <div id="PostItComment_Left">
                                        <a style="text-decoration: underline; font-weight: bold" rel="shadowbox;options{dimensions:height=800;width=790}"
                                            id="lbMemberLink" href='<%# "Member.aspx?UserId=" & eval("UserId") %>'>
                                            <img src="<%#"Images/Members/Profile/" & Eval("smPhoto") %>" alt="<%# Eval("Fullname") %>"
                                                style="border: none" />
                                        </a>
                                    </div>
                                    <div id="PostItComment_Right">
                                        <div class="postItComment_Title">
                                            <h6>
                                                <%# Eval("Fullname") %></h6>
                                            <span class="postItComment_Date">
                                                <%# Eval("Created") %></span> <span class="postItComment_Delete">
                                                    <asp:LinkButton runat="server" ID="lbDeletePostItComment" Text="X" CommandName="Select"
                                                        class="simplebtn" OnClick="lbDeletePostItComment_Click"></asp:LinkButton></span>
                                        </div>
                                        <div class="clear">
                                        </div>
                                        <div class="postItComment_comment">
                                            <%#Eval("ShareItComment")%>
                                        </div>
                                        <asp:Label ID="lblPostItCommentId" runat="server" Text='<%# Eval("PostItCommentId") %>'
                                            Visible="false" />
                                    </div>
                                </ItemTemplate>
                            </asp:TemplateField>
                        </Columns>
                    </asp:GridView>
                    <div id="postItNewComment">
                        <asp:Panel runat="server" ID="pnlComment">
                            <div style="margin: 20px 0px 10px 60px; height: 150px;">
                                <obout:Editor ID="ed_Comment" runat="server" PathPrefix="~/Controls/editor_data/"
                                    ShowQuickFormat="false" ModeSwitch="false" Submit="False" Appearance="custom"
                                    Height="120" Width="550" ClientValidation="true" AutoFocus="false" AjaxWait="false">
                                    <Buttons>
                                        <obout:Toggle Name="Bold" />
                                        <obout:Toggle Name="Italic" />
                                        <obout:Toggle Name="Underline" />
                                        <obout:HorizontalSeparator />
                                        <obout:Method Name="ForeColor" />
                                        <obout:Method Name="ForeColorClear" />
                                        <obout:Method Name="BackColor" />
                                        <obout:Method Name="BackColorClear" />
                                        <obout:HorizontalSeparator />
                                        <obout:Method Name="ClearStyles" />
                                        <obout:HorizontalSeparator />
                                        <obout:Method Name="Print" />
                                        <obout:Method Name="SpellCheck" />
                                        <obout:HorizontalSeparator />
                                        <obout:Method Name="OrderedList" />
                                        <obout:Method Name="BulletedList" />
                                        <obout:HorizontalSeparator />
                                        <obout:Method Name="ToLowerCase" />
                                        <obout:Method Name="ToUpperCase" />
                                        <obout:HorizontalSeparator />
                                        <obout:Method Name="SelectAll" />
                                        <obout:Method Name="SelectNone" />
                                        <obout:Method Name="Cut" />
                                        <obout:HorizontalSeparator />
                                        <obout:Method Name="CreateLink" />
                                    </Buttons>
                                </obout:Editor>
                                <div class="commentButtons">
                                    <asp:LinkButton runat="server" ID="ibtnAddComment" Text="Comment" TabIndex="1" ValidationGroup="comment"
                                        class="simplebtn" OnClick="ibtnAddComment_Click"></asp:LinkButton>
                                    <asp:LinkButton runat="server" ID="lbCancelComment" Text="Cancel" class="simplebtn"
                                        OnClick="lbCancelComment_Click"></asp:LinkButton>
                                    <asp:RequiredFieldValidator CssClass="req" ID="rfvComment" runat="server" ControlToValidate="ed_Comment"
                                        ErrorMessage="Comment Required" ValidationGroup="comment"></asp:RequiredFieldValidator>
                                    <asp:RegularExpressionValidator CssClass="req" ID="refComment" runat="server" ControlToValidate="ed_Comment"
                                        ErrorMessage="8000 Characters Max" ValidationExpression="^(.|\n){0,8000}$" ValidationGroup="comment"></asp:RegularExpressionValidator>
                                    <asp:Literal runat="server" ID="CommentErrorMessage"></asp:Literal>
                                    &nbsp;&nbsp;<asp:LinkButton runat="server" ID="lbCommentLogin" Text="Login" class="simplebtn"
                                        OnClick="lbCommentLogin_Click"></asp:LinkButton>
                                </div>
                            </div>
                        </asp:Panel>
                        <div class="clear">
                        </div>
                        <div class="postIt_links">
                            <div class="postIt_NewComment">
                                <asp:LinkButton runat="server" ID="ibtnComment" Text="Comment" CommandName="Select"
                                    class="simplebtn" OnClick="ibtnComment_Click"></asp:LinkButton>
                                Comments (<%# Eval("Rcount") %>)&nbsp; Like (<%# Eval("Like") %>)&nbsp;
                                <asp:LinkButton runat="server" ID="lbLike" Text="Like" CommandName="Select" OnClick="lbLike_Click"
                                    CssClass="postItButton" Font-Underline="true"></asp:LinkButton>&nbsp;&nbsp;
                                Dislike (<%# Eval("Dislike") %>)&nbsp;
                                <asp:LinkButton runat="server" ID="lbDislike" Text="Dislike" CommandName="Select"
                                    OnClick="lbDisLike_Click" CssClass="postItButton" Font-Underline="true"></asp:LinkButton>&nbsp;&nbsp;
                            </div>
                            <div class="postIt_ShareOS">
                                <a style="text-decoration: underline; font-weight: bold" rel="shadowbox;options{dimensions:height=370;width=640}"
                                    id="hypOpenShare" href='<%# "SharePostIt.aspx?PostItId=" & Eval("PostItId") %>'>
                                    <img src="Images/openshareicon.gif" alt="Open Share Icon" style="border: none" />
                                </a>
                            </div>
                            <div class="postIt_ShareFB">
                                <a name="fb_share" type="icon" share_url='<%# "SharePostIt.aspx?PostItId=" & Eval("PostItId") %>'>
                                </a>

                                <script src="http://static.ak.fbcdn.net/connect.php/js/FB.Share" type="text/javascript">
                                </script>

                                </a>
                            </div>
                        </div>
                    </div>
                </div>
                </script>
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>
   </ContentTemplate>
                </asp:UpdatePanel>

Open in new window

0
Comment
Question by:gogetsome
2 Comments
 
LVL 4

Accepted Solution

by:
Tasneem earned 500 total points
ID: 34090157
this looks like you are resetting something on the Page_OnLoad without considering the isPostback as true
0
 

Author Comment

by:gogetsome
ID: 34113747
mmm

This is my page load:

   Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            GetToday()
            lbLogin.Visible = False
            GetPostItFromSession()
            GetPostItForThreeDays()
        End If

The facebook icon disappears for any partial postback. For example, if I add a post and then GetPostItForThreeDays()
it dissapears. GetPostItForThreeDays() does repopulate the gridview that contains the facebook icon(the java button).

Is there a way to reset the javascripted button when I execute a partial postback?



    End Sub


0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
consuming an asmx web service in winforms application 3 37
Interview questions for support of a legacy ASP.NET site 4 56
Connection String 16 54
SQL Exceptions 3 43
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

816 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now