Solved

Retaining values on postback

Posted on 2004-04-09
8
1,469 Views
Last Modified: 2008-03-03
I have a repeater control.
on every postback, I do the following in my aspx.vb :

rptListing.HeaderTemplate = New RenderExecutionResourceList(ListItemType.Header)
rptListing.ItemTemplate = New RenderExecutionResourceList(ListItemType.Item)
rptListing.AlternatingItemTemplate = New RenderExecutionResourceList(ListItemType.AlternatingItem)
rptListing.FooterTemplate = New RenderExecutionResourceList(ListItemType.Footer)
--Databinding() call happens here
-----------------------------------------------------------------------------------------------------------------
Public Class RenderExecutionResourceList
    Implements ITemplate

    Public Sub InstantiateIn(ByVal container As System.Web.UI.Control) Implements System.Web.UI.ITemplate.InstantiateIn
        Dim lc As New Literal
        Select Case TemplateType
            Case ListItemType.Header
                lc.Text = "<Table border=0 cellpadding=1 cellspacing=1 "
                lc.Text &= "class=ToDoListTable width=100%>"
                lc.Text &= "<tr>"................. and so on
            Case ListItemType.Item
                AddHandler lc.DataBinding, AddressOf ExecutionResourceListItem_Databinding
            Case ListItemType.AlternatingItem
                AddHandler lc.DataBinding, AddressOf ExecutionResourceListAltItem_Databinding
            Case ListItemType.Footer
                lc.Text = "</table>"
        End Select
        container.Controls.Add(lc)
    End Sub
-----------------------------------------------------------------------------------------------------------------
    Private Sub ExecutionResourceListItem_Databinding(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim lc As Literal
        lc = CType(sender, Literal)
        Dim container As RepeaterItem
        container = CType(lc.NamingContainer, RepeaterItem)
        Dim currID As String
        currID = CType(DataBinder.Eval(container.DataItem, "ID"), String)

        lc.Text = "<tr id=row" & currID & ">"
        lc.Text &= "<input type=text size=6 id=""txtAS" & currID & """ class=""smalltextleft"" value=" & DataBinder.Eval(container.DataItem, "ProjEnd") & " onfocus=""this.blur()"" onclick=""JavaScript:updateWritein('txtAS" & currID & "'); callDiv('calspace')"">"
       lc.Text &= "</td></tr>"
    End Sub

End Class
-----------------------------------------------------------------------------------------------------------------

As you can see, I cant put these values in session variables since there could be 1 record or 500.
And I tried using server controls, but they are too expensive - page takes pretty long to load.
The user will be entering his date and could sort or something that would cause the page to postback.
I need to save the dates.

Any ideas ????
0
Comment
Question by:PBWMan
8 Comments
 
LVL 37

Expert Comment

by:gregoryyoung
ID: 10794242
I just answerre this question under another topic. The inputs are sent back during postback and are available through the request object.
0
 
LVL 28

Expert Comment

by:mmarinov
ID: 10794675
what are you actually want to store in the session obejcts ? why don't you store the whole datasource object in the session obejct
after each operation ( sort, delete or whatever ) you can set the result datasource in the session and then get it
as gregoryyoung said you can get the variables from the request.form collection but as you use repeater control the keys are not normalized e.g. repeater:_ctl0:literal0

HTH
B..M
0
 
LVL 37

Expert Comment

by:gregoryyoung
ID: 10794808
incorrect B..M the values in question are being outputted as html <input>

        lc.Text &= "<input type=text size=6 id=""txtAS" & currID & """ class=""smalltextleft"" value=" & DataBinder.Eval(container.DataItem, "ProjEnd") & " onfocus=""this.blur()"" onclick=""JavaScript:updateWritein('txtAS" & currID & "'); callDiv('calspace')"">"
0
 
LVL 28

Expert Comment

by:mmarinov
ID: 10794816
:-) gregoryyoung, so why don't you try to accept them directly to see if you will grab them as they are nested controls in the repeater web control ;-)
B..M
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 9

Expert Comment

by:malharone
ID: 10795031
use session variables! An easy solution
0
 
LVL 37

Expert Comment

by:gregoryyoung
ID: 10795309
B..M are you suggesting that .net is going in and finding his html string (placed in a literal) locating his ID= and changing it to something else ?! He does not need to access the literal control as you suggest only the actual value which was stored in the input. I would be willing to wager a significant amount of money that this is producing html with the <input> named as he has it. Renaming does not happen on text within literals I am POSITIVE of this... Of course although MSDN will back me up I am sure PBWMan could tell us for sure ...

As for Session variables they are  fairly easy they are a bit of a waste of resources it being the page is taking the time and bandwith to upload these values back to the server. Also if someone were in process of editting only the request object would know of this edit.

btw: thanks B..M I have accepted numerous LITERAL controls output through repeaters nested controls etc. Remember that a LITERAL writes its output directly and is not subject to things like you mention.
0
 
LVL 1

Author Comment

by:PBWMan
ID: 10797316
Gregoryyoung is right.
Im returning my entire table, tr, td and textboxes in plain HTML.

The user sees 50-100 rows of data and each row has a textbox.
When the user clicks the textbox, a calendar pops up and the user can select his date.
When he does this, the corresponding row has a checkbox which gets checked.

I want to save these date values as they are on every postback.
For example, the user selects 5 dates for 5 rows, and then sorts a particular column header.
My code will postback and will then build this entire HTML again - so basically I lose all the user entered data.
I cant store these values in session - since there can be as many as 500 rows.

I hope you'll understand my question better now.
0
 
LVL 37

Accepted Solution

by:
gregoryyoung earned 250 total points
ID: 10801659
you can get the changed values off of the request object PBWMan ... the browser sends up all inputs etc on the form.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now