Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Jan 2012
    Posts
    97
    Thanks
    1
    Thanked 13 Times in 13 Posts

    Asynchronous Calls

    Hey guys, so I have an update panel with some controls inside it. My problem is when ever I click either linkbutton2 or linkbutton3 for the first time, Button1 no longer fires its onclick event. I've tried setting triggers for Button1 so please don't tell me that's what I'm missing. Any help appreciated.

    Code:
                <asp:ScriptManager ID="ScriptManager1" runat="server">
                </asp:ScriptManager>
                <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Always">
                    <ContentTemplate>
                        <ul class="tabstrip">
                            <li class="<%= selected%>">
                                <asp:LinkButton ID="LinkButton2" runat="server" OnClick="LinkButton2_Click">Upcoming Events</asp:LinkButton></li><li
                                    class="<%= selectedPast%>">
                                    <asp:LinkButton ID="LinkButton3" runat="server" OnClick="LinkButton3_Click">Past Events</asp:LinkButton></li>
                        </ul>
                        <div class="panel tabs">
                            <div class="panel_sleeve">
                                <div style="display: block;">
                                    <ul class="events">
                                        <asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
                                        <asp:PlaceHolder ID="PlaceHolder5" runat="server" Visible="False"></asp:PlaceHolder>
                                    </ul>
                                </div>
                            </div>
                        </div>
                        <div class="panel">
                            <div class="panel_sleeve">
                                <h2>
                                    Comments <span class="length" id="numofcomments" runat="server"></span>
                                </h2>
                                <ul class="comments">
                                    <asp:PlaceHolder ID="PlaceHolder10" runat="server"></asp:PlaceHolder>
                                </ul>
                                <fieldset>
                                    <label>
                                        Leave a comment</label>
                                    <textarea cols="40" id="comment_body" name="comment[body]" rows="20" runat="server"></textarea>
                                </fieldset>
                                <fieldset class="submit">
                                    <asp:Button ID="Button1" runat="server" class="button" OnClick="Button1_Click" Width="148px"
                                        Height="33px" Style="background-image: url(/images/add_comment.png);" CausesValidation="False" />
                                </fieldset>
                            </div>
                        </div>
                    </ContentTemplate>
                </asp:UpdatePanel>

  • #2
    Senior Coder alykins's Avatar
    Join Date
    Apr 2011
    Posts
    1,758
    Thanks
    41
    Thanked 191 Times in 190 Posts
    would you be willing to send me the entire solution file so i can debug?

    I code C hash-tag .Net
    Reference: W3C W3CWiki .Net Lib
    Validate: html CSS
    Debug: Chrome FireFox IE

  • #3
    New Coder
    Join Date
    Jan 2012
    Posts
    97
    Thanks
    1
    Thanked 13 Times in 13 Posts
    Unfortunately no sorry, but I can paste all the relevant code for the page here if you'd like.

    Code:
    <%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true"
        CodeBehind="promoterprofile.aspx.cs" Inherits="site.promoterprofile" %>
    
    <asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
        <script runat="server">
    
            protected void LinkButton2_Click(object sender, EventArgs e)
            {
                selected = "selected";
                selectedPast = "";
                PlaceHolder1.Visible = true;
                PlaceHolder5.Visible = false;
            }
    
            protected void LinkButton3_Click(object sender, EventArgs e)
            {
                selectedPast = "selected";
                selected = "";
                PlaceHolder5.Visible = true;
                PlaceHolder1.Visible = false;
            }
    
            protected void Button1_Click(object sender, EventArgs e)
            {
                String currurl = HttpContext.Current.Request.RawUrl;
                String querystring = null;
    
                // Check to make sure some query string variables
                // exist and if not add some and redirect.
                int iqs = currurl.IndexOf('?');
                if (iqs == -1)
                {
                    String redirecturl = currurl + "?var1=1&var2=2+2%2f3&var1=3";
                    Response.Redirect(redirecturl, true);
                }
                // If query string variables exist, put them in
                // a string.
                else if (iqs >= 0)
                {
                    querystring = (iqs < currurl.Length - 1) ? currurl.Substring(iqs + 1) : String.Empty;
                }
    
                // Parse the query string variables into a NameValueCollection.
                NameValueCollection qscoll = HttpUtility.ParseQueryString(querystring);
    
                // Iterate through the collection.
                StringBuilder sb = new StringBuilder();
                foreach (String s in qscoll.AllKeys)
                {
                    sb.Append(s + qscoll[s]);
                }
    
                string commentText = comment_body.Value;
    
                if (commentText.Length < 10)
                {
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('Comments must be at least 10 characters in length.');", true);
                    return;
                }
    
                string user = HttpContext.Current.User.Identity.Name;
    
                DateTime now = DateTime.Now;
                string dateEntered = now.ToLongDateString();
                string timeEntered = now.ToLongTimeString();
    
                string date = "on " + dateEntered + " at " + timeEntered;
    
                string completePath = Server.MapPath("~/commentsXML/" + sb.ToString());
    
                if (System.IO.File.Exists(completePath))
                {
    
                    System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
    
                    //load from file
                    doc.Load(completePath);
    
                    //create node and add value
                    System.Xml.XmlNode node = doc.CreateNode(System.Xml.XmlNodeType.Element, "Comment", null);
                    node.InnerText = commentText;
    
                    System.Xml.XmlNode node3 = doc.CreateNode(System.Xml.XmlNodeType.Element, "UserName", null);
                    node3.InnerText = user;
                    node.AppendChild(node3);
    
    
                    System.Xml.XmlAttribute attr = doc.CreateAttribute("Date");
                    attr.Value = date;
    
                    node.Attributes.Append(attr);
    
                    //add to elements collection
                    doc.DocumentElement.AppendChild(node);
    
                    //save back
                    doc.Save(completePath);
    
                }
                else
                {
                    System.Xml.XmlTextWriter xWriter = new System.Xml.XmlTextWriter(System.IO.Path.Combine(completePath), Encoding.UTF8);
    
                    xWriter.WriteStartDocument();
    
                    //Create Parent elements
                    xWriter.WriteStartElement("EventComments");
                    xWriter.WriteStartElement("Comment");
    
                    xWriter.WriteAttributeString("Date", date);
                    xWriter.WriteString(commentText);
                    xWriter.WriteElementString("UserName", user);
    
                    //End writing top element and XML document
                    xWriter.WriteEndElement();
                    xWriter.WriteEndElement();
    
                    xWriter.WriteEndDocument();
    
                    xWriter.Close();
    
                }
    
                comment_body.Value = "";
                Response.Redirect(Request.RawUrl);
            }
        </script>
    </asp:Content>
    <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
        <div id="content">
            <p class="flash error" id="sa" runat="server">
            </p>
            <div id="content_main">
                <div class="panel">
                    <div class="panel_sleeve">
                        <div class="promoter_banner">
                            <asp:Image ID="bannerPic" runat="server" Height="110px" ImageUrl="" Width="590px" />
                        </div>
                        <asp:Image ID="profilePic" class="promoter_profile_image_standard" runat="server" />
                        <dl>
                            <dt>Description:</dt>
                            <dd>
                                <asp:PlaceHolder ID="PlaceHolder11" runat="server"></asp:PlaceHolder>
                            </dd>
                            <dt>Contact name:</dt>
                            <dd>
                                <asp:Label ID="Label1" runat="server"></asp:Label>
                            </dd>
                            <dt>Contact email:</dt>
                            <dd>
                                <asp:Label ID="Label2" runat="server"></asp:Label>
                            </dd>
                            <dt>Website:</dt><dd><asp:Label ID="Label3" runat="server"></asp:Label>
                            </dd>
                        </dl>
                    </div>
                </div>
                <asp:ScriptManager ID="ScriptManager1" runat="server">
                </asp:ScriptManager>
                <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Always">
                    <ContentTemplate>
                        <ul class="tabstrip">
                            <li class="<%= selected%>">
                                <asp:LinkButton ID="LinkButton2" runat="server" OnClick="LinkButton2_Click">Upcoming Events</asp:LinkButton></li><li
                                    class="<%= selectedPast%>">
                                    <asp:LinkButton ID="LinkButton3" runat="server" OnClick="LinkButton3_Click">Past Events</asp:LinkButton></li>
                        </ul>
                        <div class="panel tabs">
                            <div class="panel_sleeve">
                                <div style="display: block;">
                                    <ul class="events">
                                        <asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
                                        <asp:PlaceHolder ID="PlaceHolder5" runat="server" Visible="False"></asp:PlaceHolder>
                                    </ul>
                                </div>
                            </div>
                        </div>
                        <div class="panel">
                            <div class="panel_sleeve">
                                <h2>
                                    Comments <span class="length" id="numofcomments" runat="server"></span>
                                </h2>
                                <ul class="comments">
                                    <asp:PlaceHolder ID="PlaceHolder10" runat="server"></asp:PlaceHolder>
                                </ul>
                                <fieldset>
                                    <label>
                                        Leave a comment</label>
                                    <textarea cols="40" id="comment_body" name="comment[body]" rows="20" runat="server"></textarea>
                                </fieldset>
                                <fieldset class="submit">
                                    <asp:Button ID="Button1" runat="server" class="button" OnClick="Button1_Click" Width="148px"
                                        Height="33px" Style="background-image: url(/images/add_comment.png);" CausesValidation="False" />
                                </fieldset>
                            </div>
                        </div>
                    </ContentTemplate>
                </asp:UpdatePanel>
            </div>
            <div id="content_sub">
                <div class="panel">
                    <div class="panel_sleeve">
                        <h2>
                            Followers
                            <div style="float: right; margin-top: 3px; font-size: small; font-weight: normal;
                                font-style: normal; text-decoration: none;">
                                <asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click"></asp:LinkButton>
                            </div>
                        </h2>
                        <ul class="people" id="followers" runat="server">
                        </ul>
                    </div>
                </div>
                <div class="panel">
                    <div class="panel_sleeve">
                        <h2>
                            Videos</h2>
                        <div class="gallery">
                            <span>Videos will open in a pop-up you will not be redirected from the site.</span>
                            <br />
                            <br />
                            <asp:PlaceHolder ID="PlaceHolder4" runat="server"></asp:PlaceHolder>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </asp:Content>

  • #4
    Senior Coder alykins's Avatar
    Join Date
    Apr 2011
    Posts
    1,758
    Thanks
    41
    Thanked 191 Times in 190 Posts
    without the .sln it's hard to debug. I would try placing a break point on those calls and stepping through- see if anything happens that you're not expecting. Very hard to see the magic problem especially with AJAX (or at least it think)

    I code C hash-tag .Net
    Reference: W3C W3CWiki .Net Lib
    Validate: html CSS
    Debug: Chrome FireFox IE


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •