473,387 Members | 1,779 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

cookie textbox value problems

<asp:TextBox ID="TextBox1" runat="server" value='<%=Server.HtmlEncode
(Request.Cookies("Username")("Username"))%>'/>
<input name="Password" type="text" id="Password" value='<%
=Server.HtmlEncode(Request.Cookies("Username")("Us ername"))%>'>

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("Username")
Dim dt As DateTime = DateTime.Now()
Dim ts As New TimeSpan(1,0,10,0)

MyCookie.Expires = dt.Add(ts)
MyCookie.Domain = "jmac-solutions.com"
MyCookie.Path = "/photoshare"
MyCookie.Values("Username") = "jm*****@jmac-solutions.com"
Response.Cookies.Add(MyCookie)

End If
End Sub
</script>

code for retrieving cookie info
_________________________________
<script runat="server">
Sub Page_Load()
Dim bc As HttpBrowserCapabilities
Dim CookiesAvailable
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").Value
Response.Write(str & " <br>")

If Not Request.Cookies("Username") Is Nothing Then
Label1.Text = Server.HtmlEncode(Request.Cookies("Username")("Use rname"))
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='<%=Server.HtmlEncode
(Request.Cookies("Username")("Username"))%>'/>
<input name="Password" type="text" id="Password" value='<%
=Server.HtmlEncode(Request.Cookies("Username")("Us ername"))%>'>
</form>

--
Message posted via http://www.dotnetmonster.com
Nov 19 '05 #1
3 3966
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(Request.Cookies("Userna me")("Username"))%>'></asp:TextBox>

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

And then after setting the cookie, call TextBox1.DataBind() 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.com" <fo***@DotNetMonster.com> wrote in
message news:bd******************************@DotNetMonste r.com...
<asp:TextBox ID="TextBox1" runat="server" value='<%=Server.HtmlEncode
(Request.Cookies("Username")("Username"))%>'/>
<input name="Password" type="text" id="Password" value='<%
=Server.HtmlEncode(Request.Cookies("Username")("Us ername"))%>'>

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("Username")
Dim dt As DateTime = DateTime.Now()
Dim ts As New TimeSpan(1,0,10,0)

MyCookie.Expires = dt.Add(ts)
MyCookie.Domain = "jmac-solutions.com"
MyCookie.Path = "/photoshare"
MyCookie.Values("Username") = "jm*****@jmac-solutions.com"
Response.Cookies.Add(MyCookie)

End If
End Sub
</script>

code for retrieving cookie info
_________________________________
<script runat="server">
Sub Page_Load()
Dim bc As HttpBrowserCapabilities
Dim CookiesAvailable
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").Value
Response.Write(str & " <br>")

If Not Request.Cookies("Username") Is Nothing Then
Label1.Text =
Server.HtmlEncode(Request.Cookies("Username")("Use rname"))
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='<%=Server.HtmlEncode
(Request.Cookies("Username")("Username"))%>'/>
<input name="Password" type="text" id="Password" value='<%
=Server.HtmlEncode(Request.Cookies("Username")("Us ername"))%>'>
</form>

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

Nov 19 '05 #2
<asp:TextBox ID="TextBox1" runat="server"
Text='<%#Server.HtmlEncode(Request.Cookies("Userna me")("Username"))%
'></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(Request.Cookies("Userna me")("Username"))%
'></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
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...
9
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
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...
2
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...
3
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...
6
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...
3
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...
4
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. ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.