![]() |
| ||
| ASP.NET / C# Dynamic Control I'm having a problem with a dynamic LinkButton. For a result returned from a database query, I create two LinkButtons, dynamically. One is "Update" and the other is "Delete". I store Update or Delete in the .CommandName property. I store the identity value (the primary key) of the database record in the .CommandArgument property. All of this is in a method that is called when a user clicks a particular record displayed from a previous operation. Still with me? public void createUpDelPaper(int xPaperID, string xPaperTitle) Now, I do know about dynamic controls. The next time the page loads, these controls have to be recreated, and then the ViewState mechanism ties these "new" controls to their delegates for event processing. All well and good. But when I recreate these controls, I cannot recreate the .CommandArgument. It's a chicken-and-egg thing. I store the primary key value in the .CommandArgument so that I know which record to update or delete. But the value of .CommandArgument is set conditionally, and that condition doesn't exist on PostBack. How can I make the value persist? One answer: don't store it in .CommandArgument, put it in a ViewState variable. But this process has revealed a gap in my knowledge in how to deal with dynamically created controls. Any insights? |
| ||
| Re: ASP.NET / C# Dynamic Control It is late and I am a little tired so reading code is getting hard at this hour.... but why not store this variable value in a Session variable? |
| ||
| Re: ASP.NET / C# Dynamic Control Quote:
The real question is, why doesn't it persist through the Viewstate automatically? If you create a dynamic textbox, conditionally, say in response to some other control's click event. Then, on PostBack, you recreate a "new" TextBox with the same object name, then "magically" that new textbox becomes the dynamically-created textbox. You get all of the user-initiated and code-generated properties. What I've discovered is that, at least with ListButtons, is that the CommandArgument property doesn't act this way. |
| ||
| Re: ASP.NET / C# Dynamic Control This little problem made me delve deeply into the issues. The results of my investigation: http://www.tgreer.com/aspnet_html_04.html |
| ||
| Re: ASP.NET / C# Dynamic Control i'm doing the following and when i click the button to submit it ends up adding an additional textbox. I have a calculator where you can dynamically add controls. And I'm able to add new textboxes for additional numbers and on that same page I have a "sum values" button that does just that. The problem is that when I do a sum value it pulls the view state again and creates a new textbox. That's because for some reason my viewstate is updated after the page is created. using System; |
| All times are GMT -4. The time now is 12:21 am. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC