Go Back   CodingForums.com > :: Server side development > ASP.NET

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-20-2012, 06:06 AM   PM User | #1
sean3838
New Coder

 
Join Date: Jan 2012
Posts: 90
Thanks: 1
Thanked 13 Times in 13 Posts
sean3838 is an unknown quantity at this point
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>
sean3838 is offline   Reply With Quote
Old 10-20-2012, 08:31 PM   PM User | #2
alykins
Senior Coder

 
alykins's Avatar
 
Join Date: Apr 2011
Posts: 1,608
Thanks: 37
Thanked 183 Times in 182 Posts
alykins will become famous soon enough
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
alykins is offline   Reply With Quote
Old 10-20-2012, 08:52 PM   PM User | #3
sean3838
New Coder

 
Join Date: Jan 2012
Posts: 90
Thanks: 1
Thanked 13 Times in 13 Posts
sean3838 is an unknown quantity at this point
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>
sean3838 is offline   Reply With Quote
Old 10-21-2012, 07:19 PM   PM User | #4
alykins
Senior Coder

 
alykins's Avatar
 
Join Date: Apr 2011
Posts: 1,608
Thanks: 37
Thanked 183 Times in 182 Posts
alykins will become famous soon enough
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
alykins is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:15 PM.


Advertisement
Log in to turn off these ads.