RememberingTextBox

E

Eric B.

Hi,

I have made a RememberingTextBox.
But the remembering part is a generic function that just puts all form elements
in the session.

Is it possible to have a component that sets it's value into the session after
a form is posted?
 
L

Lewis Wang [MSFT]

Hi Eric,

Could you please explain a little bit more about what you are doing and
what you want to achieve? Thanks.

Best regards,
Lewis

This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
| From: Eric B. <none>
| Subject: RememberingTextBox
| Organization: none
| User-Agent: NewsPro/3.5.1
| Message-ID: <#[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
| Date: Fri, 22 Aug 2003 06:59:27 -0700
| NNTP-Posting-Host: yellow-rose.iu.nl 213.133.51.62
| Lines: 1
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP12.phx.gbl
| Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.aspnet.webcontrols:14139
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols
|
| Hi,
|
| I have made a RememberingTextBox.
| But the remembering part is a generic function that just puts all form
elements
| in the session.
|
| Is it possible to have a component that sets it's value into the session
after
| a form is posted?
|
|
|
 
E

Eric B.

I can see it was i bit vague.. i shall try to be more precise Lewis.

I have made a RememberingTextBox control which looks in the session for a
session variable with the same name as the name of the textbox.
When it finds a value in the session it will use this as the
RememberingTextBox's value.

I base my class on 'System.Web.UI.WebControls.TextBox'.
public class RememberingTextBox : System.Web.UI.WebControls.TextBox

I override the 'AddAttributesToRender' method to write the value attribute if
it is found in the session.
So each textbox looks in the session for the value it should use.

protected override void AddAttributesToRender(HtmlTextWriter writer)
{
string strValue = "";
if (_remember == "true")
{
if (Page.Session[ID] != null) strValue = Page.Session[ID].ToString();
}
writer.AddAttribute("value", strValue );
writer.AddAttribute("remember", _remember);
base.AddAttributesToRender(writer);
}

That is working like i want it to work.
So far so good..

However.. when the form that contains the RememberingTextBox get's post back i
am now putting the values into the session with a single function.
That will also store normal textboxesvalues and that is not nescessary.
The segment that stores it into the session looks like:

IEnumerator enumKeys = currentPage.Request.Form.Keys.GetEnumerator();
while(enumKeys.MoveNext())
{
if (enumKeys.Current.ToString().IndexOf("txt",0,3) >= 0 ||
enumKeys.Current.ToString().IndexOf("rb",0,2) >= 0 )
{
currentPage.Session.Add (enumKeys.Current.ToString(),
currentPage.Request.Form.GetValues( enumKeys.Current.ToString() ) [0].ToString
() );
}
}


As you see this just puts all (Providing the control name has 'rb' or 'txt' at
the start) control values into the session.
But i would like this process/code to be part of my control.
So the retrieval and storing of values is done automatically and a developper
should only have to put a control on the page to get the functionality.
I do not want them to explicitly call a method to store the form's values in
the session for later use.

I want to add some code, that is part of the control, to do the storing of the
value into the session.



I guess basically my question is;
Can i add code to a control that get's run serverside AFTER the control get's
posted back from a browser form?



I hope this is more clear.

Kind Regards, Eric B.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top