CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Dec 2007
    Location
    South Africa
    Posts
    263

    The function gets Fired Twice why ?

    Good Day All

    i have a function that is getting called with Page-methods like this

    Code:
      protected void Bind_SearchBox(object sender, EventArgs e)
        {
            
                RadToolBarItem textItem = RadToolBar1.FindItemByText("Button1");
                TextBox txtseach = (TextBox)textItem.FindControl("txtsearch");
                try
                {
                    if (sender.Equals(txtseach))
                    {
                        Bind_SearchBox(txtseach.Text);
                    }
                }
                catch (SqlException ex)
                {
                    lblMessage.Text = ex.Message;
                    Response.Redirect("View.aspx", false);
                }
            
        }
    and this method will call this

    Code:
     /// <summary>
        /// This Function will bind the ListBoxes on the Lefthand side of the Viewer
        /// It accept a search String
        /// </summary>
        public void Bind_SearchBox(String Search)
        {
            Session["Search"] = Search;
    
            RadPanelBar1.Items.Clear();
    
            RadScheduler1.Appointments.Clear();
            //get the Menu inside the toolbar
            RadToolBarItem textItem = RadToolBar1.FindItemByText("Button1");
            RadMenu RadMenu1 = (RadMenu)textItem.FindControl("RadMenu1");
    
    
            ViewerService.ViewerService obj = new ViewerService.ViewerService();
    
            String SessionKey = obj.newSession();
    
            DateTime Date1 = Convert.ToDateTime("1980-01-01");
    
            DateTime Date2 = Convert.ToDateTime("2012-12-31");
    
            List<string> ParentRecordsRow = new List<string>();
    
            List<string> ChildRecordsField = new List<string>();
    
            ViewerService.extract extract = obj.getObjects(SessionKey, Search, Date1, false, Date2, false, "", "");
    
            try
            {
                int Len = extract.set.Length;
                for (int i = 0; i < Len; i++)
                {
                    ViewerService.vertex value = extract.set[i];//Row
                     
                    String PanelClass = value.meta;
                    PanelClass = PanelClass.Replace(Remstr, "");
                    PanelClass = PanelClass.Replace(Remstr2, "");
                    Appointment app = null;
                    if (value.atom != null)
                    {
    
                        RadPanelItem pane = RadPanelBar1.Items.FindItemByText(PanelClass);
                        if (pane == null)
                        {
                            RadPanelItem nwpane = new Telerik.Web.UI.RadPanelItem(PanelClass);
                            RadPanelItem nwpaneSpliter = new Telerik.Web.UI.RadPanelItem(PanelClass);
                            nwpaneSpliter.IsSeparator = true;
                            RadPanelBar1.Items.Add(nwpane);
                            pane = nwpane;
                            ParentRecordsRow.Add(PanelClass);
                        }
                        if (value.meta == "za.co.abacus.C_EVENT")
                        {
                            app = new Appointment();
                        }
    
                        int atomLen = value.atom.Length;  //field
    
                        for (int j = 0; j < atomLen; j++)
                        {
                            ViewerService.atom atm = value.atom[j];
    
                            if (atm.meta.Contains("za.co.reactor.A_LABEL"))
                            {
                                RadPanelItem NewItem = new RadPanelItem(atm.content);
    
                                pane.Items.Add(NewItem);
    
                                ChildRecordsField.Add(atm.content);
    
                                if (app != null)
                                {
                                    app.Subject = atm.content;
                                    app.Description = atm.content;
                                    app.ID = value.key;
                                }
    
                            }
    
                            if (app != null && atm.meta.Contains("za.co.abacus.C_EVENT"))
                            {
                                app.ID = atm.content;
                            }
                            if (app != null && atm.meta.Contains("za.co.reactor.A_HORIZON"))
                            {
                                app.Start = Convert.ToDateTime(atm.content);
                            }
                            if (app != null && atm.meta.Contains("za.co.reactor.AA_HORIZON"))
                            {
                                app.End = Convert.ToDateTime(atm.content);
                            }
                            if (app != null && atm.meta.Contains("za.co.reactor.A_TEXT"))
                            {
                                app.Description = atm.content;
                            }       
     
                            if (app != null && app.End > app.Start)
                            {
                                RadScheduler1.DataStartField = app.Start.ToString();
                                RadScheduler1.DataSubjectField = app.Subject.ToString();
                                RadScheduler1.DataEndField = app.End.ToString();
                                RadScheduler1.DataKeyField = app.ID.ToString();
                                RadScheduler1.SelectedView = SchedulerViewType.MonthView;
                                AddManualAppointments(app.ID.ToString(), app.Start, app.End, app.Subject.ToString());
                                RadScheduler1.SelectedDate = app.Start;
                                RadScheduler1.Visible = true;
                                LeftPane.Collapsed = false;
                                RadGrid1.DataSource = EAVProcess.GetRecords(ParentRecordsRow, ChildRecordsField);
                                RadGrid1.DataBind();
    
                            }
                        }
    
    
                    }
    
                }
                RadMenu1.Flow = ItemFlow.Horizontal;
    
                //Add the Root
                RadMenuItem item = new RadMenuItem();
                item.Text = "";
                item.ImageUrl = "~/images/Add.png";
                RadMenu1.Items.Add(item);
                //Bind Men
                for (int KK = 0; KK < ParentRecordsRow.Count; KK++)
                {
    
                    RadMenuItem itemSeparator = new RadMenuItem();
    
                    RadMenuItem childItem = new RadMenuItem(ParentRecordsRow[KK]);
                    //add the menu items
                    childItem.Text = ParentRecordsRow[KK];
                    //item.ImageUrl = "~/images/o!logo.png";
                    item.Items.Add(childItem);
    
    
                }
                 
            }
            catch (ApplicationException ex)
            {
                lblTestlabel.Text = ex.Message;
    
            }
            finally
            {
       
                obj.closeSession(SessionKey);
                obj = null;
                extract = null;
            }
     
    
        }

    and the page method for the client side

    Code:
       [WebMethod, System.Web.Script.Services.ScriptMethod]
        public static string Getadata(String StrSearch)
        {
            View obj = new View();
            obj.Bind_SearchBox(StrSearch);
            return StrSearch;
        }
    and on the client side

    Code:
      function keyPress_test() 
         {
          
            var tb = document.getElementById("<%=txtsearchid%>");
           
            if (window.event.keyCode == 13)
             {
                 PageMethods.Getadata(tb.value, myFunction(tb.Value));
                
                ToggleCollapsePane();
            }
            return false;
         }
     
     
        function myFunction(msg) {
            alert(msg);
        }

    So when i press enter it start searching and do all the data binding , now its fine but i went to debug it and i saw that this gets fired twice

    What is wrong ?

    Thanks
    Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers."

  2. #2
    Join Date
    Feb 2005
    Location
    Denmark
    Posts
    742

    Re: The function gets Fired Twice why ?

    If this is happening only when debugging, then you can use the stack trace.
    When entering the method the first and second time, check out the stack trace and you should see which functionality is calling your function.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured