Solved

Retaining values on postback

Posted on 2004-04-09
8
1,475 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
The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

 
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
 
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

830 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