0
Reply

event problem

ikirkland

ikirkland

Apr 16 2004 11:00 AM
1.5k
Hi, I am having this issue with web forms, and not quite sure how I keep hitting the same problem, basically it appears as if my events only fire the second time round... For example, I have a list of UI items, dynamically generated and I make myself a private property to make it easier to get/set stuff into the ViewState [code] private bool LimitLocation { get { if(ViewState["LimitLocation"]==null) { ViewState["LimitLocation"] = false; } return (bool)ViewState["LimitLocation"]; } set { ViewState["LimitLocation"] = value; } } [/code] Now I use this to determine wether items in my list should show or not, here is the code that dynamically generates the UI controls which checks property Location limit within the foreach loop (lb.Visible= this.LimitLocation;) : [code] private void HandleBrowseJobs() { foreach(JobOption jop in jobOptionCollection) { // sort out region stuff if(jop.CategoryValue=="Region") { LinkButton lb = new LinkButton(); lb.Text = jop.OptionValue; lb.ID = jop.CategoryValue + jop.OptionValue; lb.Command +=new CommandEventHandler(this.lb_Command); lb.CommandArgument = jop.CategoryValue; if(lblLocationOptions.Controls.Count/2>=this.OptionLimit) { lb.Visible= this.LimitLocation; } LiteralControl lc = new LiteralControl("
"); this.lblLocationOptions.Controls.Add(lb); this.lblLocationOptions.Controls.Add(lc); } } } [/code] When the page first loads the property LocationLimit is set to false, here is the code that decides wether to show another option ("More regions..." ) based on the LimitLocation property to with its respective event handler moreOptions_Command : [code] if(lblLocationOptions.Controls.Count/2>this.OptionLimit && this.LimitLocation==false) { LinkButton moreOptions = new LinkButton(); moreOptions.Text = "More Regions..."; moreOptions.CommandArgument = "Location"; moreOptions.Command += new CommandEventHandler(moreOptions_Command); this.lblLocationOptions.Controls.Add(moreOptions); LiteralControl lc = new LiteralControl("
"); this.lblLocationOptions.Controls.Add(lc); } [/code] Finally here is my event handler : [code] private void moreOptions_Command(object sender, CommandEventArgs e) { Response.Write("EVENT FIRED!!!!!!!"); switch(e.CommandArgument.ToString()) { case "Location" : this.LimitLocation = true; break; case "Salary" : this.LimitSalary = true; break; case "Role" : this.LimitRole = true; break; case "SubRole" : this.LimitSubRole = true; break; case "Sector" : this.LimitSector = true; break; } HandleBrowseJobs(); } [/code] I have not provided the entire script here, however the problem I am getting is the event only fires when I click the "More Regions..." twice :( . Hope someone can help me with this prob, I am sure I am doing something really dumb :( regards Ian