473,543 Members | 2,466 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

cookie textbox value problems

<asp:TextBox ID="TextBox1" runat="server" value='<%=Serve r.HtmlEncode
(Request.Cookie s("Username")(" Username"))%>'/>
<input name="Password" type="text" id="Password" value='<%
=Server.HtmlEnc ode(Request.Coo kies("Username" )("Username"))% >'>

i have created a cookie and want to use it with my login page. I currently
have asp:TextBox with form validation control. I can get the cookie value
to appear but not in the asp:TextBox. I can use a label to show it on the
page or in a standard HTML text field. I don't understand what is going
on. Can we not bind values to the asp:TextBox?

code for setting cookie works
_______________ ______________
<script runat="server">
Sub Page_Load(Src As Object, E As EventArgs)
If NOT IsPostBack Then
Dim MyCookie As HttpCookie = New HttpCookie("Use rname")
Dim dt As DateTime = DateTime.Now()
Dim ts As New TimeSpan(1,0,10 ,0)

MyCookie.Expire s = dt.Add(ts)
MyCookie.Domain = "jmac-solutions.com"
MyCookie.Path = "/photoshare"
MyCookie.Values ("Username") = "jm*****@jm ac-solutions.com"
Response.Cookie s.Add(MyCookie)

End If
End Sub
</script>

code for retrieving cookie info
_______________ _______________ ___
<script runat="server">
Sub Page_Load()
Dim bc As HttpBrowserCapa bilities
Dim CookiesAvailabl e
bc = Request.Browser
If bc.Cookies Then
Message.Text = "Cookies are available with this browser.<br>"
Message.Text &= "Save login info?: <input type=checkbox name=checkbox
value=checkbox> "
Else
Message.Text = "Cookies are NOT available with this browser"

End If

Dim str As String
str = Request.Cookies ("Username").Va lue
Response.Write( str & " <br>")

If Not Request.Cookies ("Username") Is Nothing Then
Label1.Text = Server.HtmlEnco de(Request.Cook ies("Username") ("Username") )
End If
End Sub
</script>

<form runat="server">
<asp:Label id="Message" runat="server" /><br>
<asp:Label id="Label1" runat="server" /> <br>
<asp:TextBox ID="TextBox1" runat="server" value='<%=Serve r.HtmlEncode
(Request.Cookie s("Username")(" Username"))%>'/>
<input name="Password" type="text" id="Password" value='<%
=Server.HtmlEnc ode(Request.Coo kies("Username" )("Username"))% >'>
</form>

--
Message posted via http://www.dotnetmonster.com
Nov 19 '05 #1
3 3979
The syntax you use, is not databinding syntax but tells Page to write the
string out at rendering stage. And as you use single quotes, it doesn't
indeed work with TextBox (it also takes the text into its Text property) but
comes out as a literal string as TextBox's text. If you change single quotes
to double quotes, you get error stating that <%...%> construct cannot be
used inside server-side tags.

You have two solutions:

- Set the Text property in code

OR

Change databinding syntax in textBox as follows (to the ASP.NET's correct
databinding syntax)

<asp:TextBox ID="TextBox1" runat="server"
Text='<%#Server .HtmlEncode(Req uest.Cookies("U sername")("User name"))%>'></asp:TextBox>

(Note the <%#...%> construct)

And then after setting the cookie, call TextBox1.DataBi nd() to initiate
databinding (or if you have call to Page.DataBind() which does for entire
page, that's fine too unless you want to bind only a specific control)

--
Teemu Keiski
ASP.NET MVP, Finland
"Justin Morris via DotNetMonster.c om" <fo***@DotNetMo nster.com> wrote in
message news:bd******** *************** *******@DotNetM onster.com...
<asp:TextBox ID="TextBox1" runat="server" value='<%=Serve r.HtmlEncode
(Request.Cookie s("Username")(" Username"))%>'/>
<input name="Password" type="text" id="Password" value='<%
=Server.HtmlEnc ode(Request.Coo kies("Username" )("Username"))% >'>

i have created a cookie and want to use it with my login page. I
currently
have asp:TextBox with form validation control. I can get the cookie value
to appear but not in the asp:TextBox. I can use a label to show it on the
page or in a standard HTML text field. I don't understand what is going
on. Can we not bind values to the asp:TextBox?

code for setting cookie works
_______________ ______________
<script runat="server">
Sub Page_Load(Src As Object, E As EventArgs)
If NOT IsPostBack Then
Dim MyCookie As HttpCookie = New HttpCookie("Use rname")
Dim dt As DateTime = DateTime.Now()
Dim ts As New TimeSpan(1,0,10 ,0)

MyCookie.Expire s = dt.Add(ts)
MyCookie.Domain = "jmac-solutions.com"
MyCookie.Path = "/photoshare"
MyCookie.Values ("Username") = "jm*****@jm ac-solutions.com"
Response.Cookie s.Add(MyCookie)

End If
End Sub
</script>

code for retrieving cookie info
_______________ _______________ ___
<script runat="server">
Sub Page_Load()
Dim bc As HttpBrowserCapa bilities
Dim CookiesAvailabl e
bc = Request.Browser
If bc.Cookies Then
Message.Text = "Cookies are available with this browser.<br>"
Message.Text &= "Save login info?: <input type=checkbox name=checkbox
value=checkbox> "
Else
Message.Text = "Cookies are NOT available with this browser"

End If

Dim str As String
str = Request.Cookies ("Username").Va lue
Response.Write( str & " <br>")

If Not Request.Cookies ("Username") Is Nothing Then
Label1.Text =
Server.HtmlEnco de(Request.Cook ies("Username") ("Username") )
End If
End Sub
</script>

<form runat="server">
<asp:Label id="Message" runat="server" /><br>
<asp:Label id="Label1" runat="server" /> <br>
<asp:TextBox ID="TextBox1" runat="server" value='<%=Serve r.HtmlEncode
(Request.Cookie s("Username")(" Username"))%>'/>
<input name="Password" type="text" id="Password" value='<%
=Server.HtmlEnc ode(Request.Coo kies("Username" )("Username"))% >'>
</form>

--
Message posted via http://www.dotnetmonster.com

Nov 19 '05 #2
<asp:TextBox ID="TextBox1" runat="server"
Text='<%#Server .HtmlEncode(Req uest.Cookies("U sername")("User name"))%
'></asp:TextBox>


i had tried with this syntax # also, it still didn't work just a blank box.
Please help-

--
Message posted via http://www.dotnetmonster.com
Nov 19 '05 #3
Don't use <asp:TextBox> unless you need to:

<input type=input value=<%= Session("fooey" )%>

If you do need it on the server as a full blown TextBox, then do the assignment
in code, not inline in the ASPX.

<asp:TextBox runat=server id=_name />

Sub Page_Load()
_name.Text = Sesison("fooey" )
End Sub

-Brock
DevelopMentor
http://staff.develop.com/ballen
<asp:TextBox ID="TextBox1" runat="server"
Text='<%#Server .HtmlEncode(Req uest.Cookies("U sername")("User name"))%
'></asp:TextBox>

i had tried with this syntax # also, it still didn't work just a blank
box. Please help-


Nov 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
2096
by: Manlio Perillo | last post by:
Hi. I'm using the Cookie module (on the client side). I have found a problem trying to parse the cookie: "Set-Cookie: value=thevalue; path=/; expires=Fri, 21-May-2004 10:40:51 GMT" The date is not parsed correctly, only "Fri," is matched.
9
1858
by: vbMark | last post by:
What am I doing wrong here? <% UserID = Request.Cookies("emu")("UserID") %> <TABLE> <TR> <TD>UserID: <INPUT id=UserID value="<%=UserID%>"></TD> </TR>
1
2299
by: Chris Kennedy | last post by:
I am writing the value from a textarea input box to a cookie. Long story but when I return to the page I want to pull the value from the cookie and put it back in the textbox. When I do this all the linebreaks and spaces are removed. Here is the longer version of the problem if it helps. Essentially I have a page which sends some form...
2
3722
by: Alan Silver | last post by:
Hello, I have discovered that if I try and add a cookie when one by that already exists, nothing happens. No error, but the cookie is not set to the new value. For example (this is running in a DLL, which is why I use HttpContext)... HttpCookie cookie = new HttpCookie("fred", "ferret");
3
2139
by: Nalaka | last post by:
Hi, I have a textbox, I need to set a cookie to the value of the textbox... when textbox.Text changes. How do I do this using clientSide script (javascript) only. I do not want to post back to the server and then set the cookie using server script. Any help is very appretiated (I did search the internet)...
6
4349
by: Victor | last post by:
Hi everybody, could anybody help me with the following problem : I need to set a cookie containing a Russian character string as the value, using the construct "document.cookie = ...". The whole project runs in the UTF-8 encoding. The Internet Explorer handles this cookie correctly, whereas the FireFox writes only some byte gargabe and...
3
1981
by: StevenT | last post by:
Hello, I am trying to dynamically create a table based on the information I have in my cookie for a shopping cart. I can create it and display it and all is good. I put the contents of the cookie into a multidimensional array and loop through the array creating rows and cells based on the information. I create TextBox's and add them to the...
4
2288
by: =?Utf-8?B?YW5vb3A=?= | last post by:
hello, I am writing the Following coding for preventing Session Fixation attack in ASP.Net website, but I could not retrieve the cookie added and the value of cookie_value remains blank. ---------------------------------------------------------- Imports System.Web.UI.WebControls
0
7349
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7590
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7688
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5885
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5271
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3391
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1817
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
968
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
636
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.