Need help with loading rows of input controls one at a time
-
To begin with I AM NOT AN ASP.NET Coder. So please bear with me and my questions. I have to build this in asp instead of silverlight so it can be accessed on blackberries. I have a page that collects a ton of data about where a link will be started. The engineers then construct 4-8 links to the endpoint terminus. What I'm trying to do is have each link get added to the list of links until they click the done button. Each 'link' in the list would be as follows: lable'Leg ' lable'nn' text' ' button[next link] button[done] the lable with the 'nn' value is populated by me and is 1, 2, 3, 4, etc. the button with [next link] would trigger adding the next set of lables, textbox, and buttons. the button with [done] would populate the database with all of the links. In a prior post I was given invalid control types to use and the person never answered me after that. So how would I do this in ASP.Net so that the input is always sent back to me and the next link is added to the list with each postback?
-
To begin with I AM NOT AN ASP.NET Coder. So please bear with me and my questions. I have to build this in asp instead of silverlight so it can be accessed on blackberries. I have a page that collects a ton of data about where a link will be started. The engineers then construct 4-8 links to the endpoint terminus. What I'm trying to do is have each link get added to the list of links until they click the done button. Each 'link' in the list would be as follows: lable'Leg ' lable'nn' text' ' button[next link] button[done] the lable with the 'nn' value is populated by me and is 1, 2, 3, 4, etc. the button with [next link] would trigger adding the next set of lables, textbox, and buttons. the button with [done] would populate the database with all of the links. In a prior post I was given invalid control types to use and the person never answered me after that. So how would I do this in ASP.Net so that the input is always sent back to me and the next link is added to the list with each postback?
A few ways you could do it. Use a repeater control with a template that contains the label the textbox controls Pseudo code here <repeater> <template> <label> <textbox> </template> </repeater> <button value=Next><button value=Done> Bind the repeater to some collection. Handle the click event for the button and add an item to the collection, then rebind to the repeater. Another way is to handle the click event for the button and add the next set of controls to the controls collection of the page.
only two letters away from being an asset
-
A few ways you could do it. Use a repeater control with a template that contains the label the textbox controls Pseudo code here <repeater> <template> <label> <textbox> </template> </repeater> <button value=Next><button value=Done> Bind the repeater to some collection. Handle the click event for the button and add an item to the collection, then rebind to the repeater. Another way is to handle the click event for the button and add the next set of controls to the controls collection of the page.
only two letters away from being an asset
Mark, Thank you so much. I have everything almost working. After a little debugging I found I had to code a bit to rebuild the collection of values for each new connection added. Now I have just a tiny issue I cannot figure out. My logic is quite simple:
protected void NextLegEventHandler( object sender, EventArgs e ) { LegItem legItem = new LegItem( ); legNames = new Dictionary<int, LegItem>( ); foreach ( Control item in LegConstructor.Controls ) { if ( !( item is RepeaterItem ) ) continue; if ( item.Controls.Count <= 1 ) continue; foreach ( Control textItem in item.Controls ) { TextBox currentControl = textItem as TextBox; if ( currentControl == null ) continue; int result = 0; if ( Int32.TryParse( currentControl.Text, out result ) ) { legItem = new LegItem( ); legItem.LegNumber = result; } else { legItem.PortName = currentControl.Text; legNames.Add( legItem.LegNumber, legItem ); } } } LegItem newLeg = new LegItem( ); newLeg.LegNumber = legNames.Count + 1; newLeg.PortName = string.Empty; legNames.Add( newLeg.LegNumber, newLeg ); this.LegConstructor.DataSource = legNames.Values.ToArray<LegItem>( ); this.LegConstructor.DataBind( ); }
So this way I rebuild the values for each leg and rebind with the new list. The problem: I have to hit the button twice to get the new entry to display! What am I missing to force the page to display the new data once I complete my response to the event? Thanks again, Michael
-
Mark, Thank you so much. I have everything almost working. After a little debugging I found I had to code a bit to rebuild the collection of values for each new connection added. Now I have just a tiny issue I cannot figure out. My logic is quite simple:
protected void NextLegEventHandler( object sender, EventArgs e ) { LegItem legItem = new LegItem( ); legNames = new Dictionary<int, LegItem>( ); foreach ( Control item in LegConstructor.Controls ) { if ( !( item is RepeaterItem ) ) continue; if ( item.Controls.Count <= 1 ) continue; foreach ( Control textItem in item.Controls ) { TextBox currentControl = textItem as TextBox; if ( currentControl == null ) continue; int result = 0; if ( Int32.TryParse( currentControl.Text, out result ) ) { legItem = new LegItem( ); legItem.LegNumber = result; } else { legItem.PortName = currentControl.Text; legNames.Add( legItem.LegNumber, legItem ); } } } LegItem newLeg = new LegItem( ); newLeg.LegNumber = legNames.Count + 1; newLeg.PortName = string.Empty; legNames.Add( newLeg.LegNumber, newLeg ); this.LegConstructor.DataSource = legNames.Values.ToArray<LegItem>( ); this.LegConstructor.DataBind( ); }
So this way I rebuild the values for each leg and rebind with the new list. The problem: I have to hit the button twice to get the new entry to display! What am I missing to force the page to display the new data once I complete my response to the event? Thanks again, Michael
Why are you going through all of this :wtf: :omg: Maintain your collection (as in ViewState, Session, etc.), add one to it in the handler, then rebind. What is the dictionary for? You are only using the values from it.
Michael Eber wrote:
I AM NOT AN ASP.NET Coder.
Whether you are an ASP.NET coder or not, someone with your professed skills and length of C# history should be able to figure this out. After writing a new multitasking operating system in Assembler this should be a walk in the park.
only two letters away from being an asset
-
Why are you going through all of this :wtf: :omg: Maintain your collection (as in ViewState, Session, etc.), add one to it in the handler, then rebind. What is the dictionary for? You are only using the values from it.
Michael Eber wrote:
I AM NOT AN ASP.NET Coder.
Whether you are an ASP.NET coder or not, someone with your professed skills and length of C# history should be able to figure this out. After writing a new multitasking operating system in Assembler this should be a walk in the park.
only two letters away from being an asset
Sorry but I'm accustomed to writing code that is stateful where I can just access the datasource, cast it, and append to it. Web coding is a completely different animal. Regardless of HOW I am doing it, whether I figure out how to use ViewState or if I figure out Session, it does not change the fact that when I set my datasource and rebind it, my controls are not displaying until I hit the button twice, or slowly walk through the code in debug mode. Why is this happening? In a real application (ie. not a freaking web p.o.s.) this is always easily figured out. But I cannot figure out why I must hit the button twice to see my control. You say just rebind it. Well I am rebinding the fracking array. And it is not doing it. If you have something USEFUL to add, please I'm all ears. But if you don't then thank you for at least getting me this far.
-
Why are you going through all of this :wtf: :omg: Maintain your collection (as in ViewState, Session, etc.), add one to it in the handler, then rebind. What is the dictionary for? You are only using the values from it.
Michael Eber wrote:
I AM NOT AN ASP.NET Coder.
Whether you are an ASP.NET coder or not, someone with your professed skills and length of C# history should be able to figure this out. After writing a new multitasking operating system in Assembler this should be a walk in the park.
only two letters away from being an asset
Oh yes...another reason for doing this is to get the responses in all of the textboxes. Does that pass back in Viewstate as well? I dug through two obvious routes (control and Page) but nothing is there to access ViewState.
-
Oh yes...another reason for doing this is to get the responses in all of the textboxes. Does that pass back in Viewstate as well? I dug through two obvious routes (control and Page) but nothing is there to access ViewState.
Maintaining a control's state between requests is the purpose of ViewState (besides bloating the page :)) http://msdn.microsoft.com/en-us/library/ms972976.aspx[^]
only two letters away from being an asset
-
Maintaining a control's state between requests is the purpose of ViewState (besides bloating the page :)) http://msdn.microsoft.com/en-us/library/ms972976.aspx[^]
only two letters away from being an asset
Thank you for a usable answer. So it seems that the viewstate is updated prior to reaching my method ... that adds the new control. So it appears that for the webpage if I instantiate the viewstate update method after binding, then the control should show properly on the outbound process.
-
Thank you for a usable answer. So it seems that the viewstate is updated prior to reaching my method ... that adds the new control. So it appears that for the webpage if I instantiate the viewstate update method after binding, then the control should show properly on the outbound process.
A true professional would have been able to research this for themself
only two letters away from being an asset
-
A true professional would have been able to research this for themself
only two letters away from being an asset
Ahhh yes, you are two letters short of an asset.