Solved

Retaining values on postback

Posted on 2004-04-09
8
1,470 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
C# GridRow get Old/New Value 1 55
insert image with its metadata into SQL server Database 3 89
Error on Add method 1 38
Visual Studio TFS - how do I check in my code? 2 29
This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

920 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

16 Experts available now in Live!

Get 1:1 Help Now