Showing posts with label database. Show all posts
Showing posts with label database. Show all posts

Thursday, March 29, 2012

Passing Value Query

Hi,

I have an e-commerce website written in asp 1.1, vb.net and utilising an access database. Within the database I have a ProductID value to identify each product. Within the following sub procedure I want to be able to reference this value as I want to be able to check if there are enough items in stock. The code below uses the cartitemID and quantity as variables. However to reference individual items in the database I surely will need to pass the ProductID value. How should I approach this ?

[CODE]

Sub dgCart_Update(sender As Object, e As DataGridCommandEventArgs)

Dim intCartitemID As Integer
Dim txtQuantity As TextBox
Dim intQuantity As Integer

'Passes ProductID as sender

'Dim intProductID As Integer ??

intCartitemID = dgCart.DataKeys(e.Item.ItemIndex)
txtQuantity = e.Item.FindControl("txtQuantity")
intQuantity = txtQuantity.Text

'Define intQuantityInStock and reference to CheckQuantity function
Dim intQuantityInStock As Integer = CheckQuantity(intProductID)

'If statement to check enough quantity in stock
If intQuantityInStock < intQuantity
lblError.Text = "This item is currently low in stock. Please select an alternative</b>"
lblError.Visible = True
Else
Dim strSQL As String = "UPDATE [tblCartItems] SET [intQuantityOrder]=@dotnet.itags.org.Quantity WHERE "& _
"intCartitemID = @dotnet.itags.org.intCartitemID"

Dim dbCommand As New OleDbCommand(strSQL, dbConnection)

Dim cmd As New OleDbCommand

dbCommand.Parameters.Add("@dotnet.itags.org.Quantity", intQuantity)
dbCommand.Parameters.Add("@dotnet.itags.org.intCartitemID", intCartitemID)

dbConnection.Open()
dbCommand.ExecuteNonQuery()
dbConnection.Close()

dgCart.EditItemIndex = -1
dgCart.DataSource = DisplayCart()
dgCart.DataBind()

End If

End Sub
[/CODE]

You should be able to set this value in, say the CommandArgument of the button that is being clicked

ex:

<asp:Button
ID="btnAddToCart" runat="server"
CommandArgument='<%# Eval( "ProductID" ) %>'
CommandName="Product"
Text="Add To Cart" />

Then in your code behind, assign intProductID = (int) e.CommandArgument

Depending on what else you are doing with your grid, you may have to wrap an "if" around some code, checking if e.CommandName == "Product"


Thanks - unfortunately I'm not using a button in this instance. How else could I approach it ?


Fixed it thanks

Passing values between pages using Forms Authentication

I want to know how can i pass a value from my database to another page using Forms Authentication.

In this example:

1Sub Logon_Click(ByVal senderAs Object,ByVal eAs EventArgs)Handles Submit1.Click23Dim objConnectionAs Data.SqlClient.SqlConnection4Dim objCommandAs Data.SqlClient.SqlCommand5Dim usernameAs String6 Dim passwordAs String7 Dim strSQLQueryAs String8 Dim RecordCountAs Integer910 username = userTextBox.Text11 password = passTextBox.Text1213If Len(Trim(username)) > 0Then14 objConnection =New Data.SqlClient.SqlConnection("Data Source=localhost;" _15 &"Initial Catalog=web_dados;User Id=sa;Password=platinum;" _16 &"Connect Timeout=15;")1718 strSQLQuery ="SELECT * FROM conserto WHERE web_user ='" & username & "' AND web_pass = '" & password & "' "19 objCommand = New Data.SqlClient.SqlCommand(strSQLQuery, objConnection)202122 Try23 objConnection.Open()24 RecordCount = CInt(objCommand.ExecuteScalar())25 Catch ex As Exception26 Finally27 objConnection.Close()28 End Try2930 If RecordCount = 0 Then31 Msg.Text = "Identificação de conserto ou código de acesso inválido."32Else33 FormsAuthentication.RedirectFromLoginPage _34 (userTextBox.Text, Persist.Checked)35End If3637 objConnection.Close()38End If394041 End Sub42

I want to store the value of the field named <numero> of the database, and when the user authenticates, i want to print that variable in the default.aspx page.

You can use a Session variable to do so. If you are using ASP.NET 2.0, then you could use a Profile object too.

Does this help?

Regards


i've just tried to use sessions, but when the user autheticates and are redirected to the default.aspx page, it lost the session value.

1 username = userTextBox.Text2 password = passTextBox.Text3 Session("USERNAME") = username45If Len(Trim(username)) > 0Then6 objConnection =New Data.SqlClient.SqlConnection("Data Source=localhost;" _7 &"Initial Catalog=web_dados;User Id=sa;Password=platinum;" _8 &"Connect Timeout=15;")910 strSQLQuery ="SELECT * FROM conserto WHERE web_user ='" & username & "' AND web_pass = '" & password & "' "11 objCommand = New Data.SqlClient.SqlCommand(strSQLQuery, objConnection)121314 Try15 objConnection.Open()16 RecordCount = CInt(objCommand.ExecuteScalar())17 Catch ex As Exception18 Finally19 objConnection.Close()20 End Try2122 If RecordCount = 0 Then23 Msg.Text = "Identificação de conserto ou código de acesso inválido."24Else2526 FormsAuthentication.RedirectFromLoginPage _27 (userTextBox.Text, Persist.Checked)

in this code in the default.aspx it doesn't display any value.

1Sub Page_Load(ByVal SrcAs Object,ByVal eAs EventArgs)2 userLabel.Text = Session("USERNAME")3End Sub4

why?

Saturday, March 24, 2012

passing variables between pages

I have a web app that searches a database and returns a datagrid table.
the user inputs the search terms into a textbox. The user selects the
info he wants and it sends him to a 2nd page, after another selection
it goes to a 3rd page. I have been able to pass the search term in my
textbox back and forth to all the pages using Context.items. Now the
user may click a button that is supposed to take him back to the first
page and reload the original datagrid. How do I get the variable
containing the search terms from the 3rd page back to the 1st page and
automatically perform the search or is there another way to recall the
datagrid? thanks.Why won't you put it in a session variable?

Eliyahu

<lacombpcs@.juno.com> wrote in message
news:1117539066.532083.18140@.g49g2000cwa.googlegro ups.com...
> I have a web app that searches a database and returns a datagrid table.
> the user inputs the search terms into a textbox. The user selects the
> info he wants and it sends him to a 2nd page, after another selection
> it goes to a 3rd page. I have been able to pass the search term in my
> textbox back and forth to all the pages using Context.items. Now the
> user may click a button that is supposed to take him back to the first
> page and reload the original datagrid. How do I get the variable
> containing the search terms from the 3rd page back to the 1st page and
> automatically perform the search or is there another way to recall the
> datagrid? thanks.
You could session variables (as already mentioned), you could still use
context items provided you know what the originating page was (ie. the fact
it came from the 3rd page). You could use an argument in the URL/query
string to set this. You could also save his info to a database, and use the
query string info to flag a reload of that info from the database.

There are many options.

--

- Paul Glavich
ASP.NET MVP
ASPInsider (www.aspinsiders.com)

<lacombpcs@.juno.com> wrote in message
news:1117539066.532083.18140@.g49g2000cwa.googlegro ups.com...
> I have a web app that searches a database and returns a datagrid table.
> the user inputs the search terms into a textbox. The user selects the
> info he wants and it sends him to a 2nd page, after another selection
> it goes to a 3rd page. I have been able to pass the search term in my
> textbox back and forth to all the pages using Context.items. Now the
> user may click a button that is supposed to take him back to the first
> page and reload the original datagrid. How do I get the variable
> containing the search terms from the 3rd page back to the 1st page and
> automatically perform the search or is there another way to recall the
> datagrid? thanks.

passing variables between pages

I have a web app that searches a database and returns a datagrid table.
the user inputs the search terms into a textbox. The user selects the
info he wants and it sends him to a 2nd page, after another selection
it goes to a 3rd page. I have been able to pass the search term in my
textbox back and forth to all the pages using Context.items. Now the
user may click a button that is supposed to take him back to the first
page and reload the original datagrid. How do I get the variable
containing the search terms from the 3rd page back to the 1st page and
automatically perform the search or is there another way to recall the
datagrid? thanks.can u keep the search variables in session?
bineesh
<lacombpcs@.juno.com> wrote in message
news:1117539066.532083.18140@.g49g2000cwa.googlegroups.com...
> I have a web app that searches a database and returns a datagrid table.
> the user inputs the search terms into a textbox. The user selects the
> info he wants and it sends him to a 2nd page, after another selection
> it goes to a 3rd page. I have been able to pass the search term in my
> textbox back and forth to all the pages using Context.items. Now the
> user may click a button that is supposed to take him back to the first
> page and reload the original datagrid. How do I get the variable
> containing the search terms from the 3rd page back to the 1st page and
> automatically perform the search or is there another way to recall the
> datagrid? thanks.
>
Why won't you put it in a session variable?
Eliyahu
<lacombpcs@.juno.com> wrote in message
news:1117539066.532083.18140@.g49g2000cwa.googlegroups.com...
> I have a web app that searches a database and returns a datagrid table.
> the user inputs the search terms into a textbox. The user selects the
> info he wants and it sends him to a 2nd page, after another selection
> it goes to a 3rd page. I have been able to pass the search term in my
> textbox back and forth to all the pages using Context.items. Now the
> user may click a button that is supposed to take him back to the first
> page and reload the original datagrid. How do I get the variable
> containing the search terms from the 3rd page back to the 1st page and
> automatically perform the search or is there another way to recall the
> datagrid? thanks.
>
You could session variables (as already mentioned), you could still use
context items provided you know what the originating page was (ie. the fact
it came from the 3rd page). You could use an argument in the URL/query
string to set this. You could also save his info to a database, and use the
query string info to flag a reload of that info from the database.
There are many options.
- Paul Glavich
ASP.NET MVP
ASPInsider (www.aspinsiders.com)
<lacombpcs@.juno.com> wrote in message
news:1117539066.532083.18140@.g49g2000cwa.googlegroups.com...
> I have a web app that searches a database and returns a datagrid table.
> the user inputs the search terms into a textbox. The user selects the
> info he wants and it sends him to a 2nd page, after another selection
> it goes to a 3rd page. I have been able to pass the search term in my
> textbox back and forth to all the pages using Context.items. Now the
> user may click a button that is supposed to take him back to the first
> page and reload the original datagrid. How do I get the variable
> containing the search terms from the 3rd page back to the 1st page and
> automatically perform the search or is there another way to recall the
> datagrid? thanks.
>

Passing Variables Between Pages

I have a problem passing information between pages.

I have a page (SendingPage.aspx) that uses the DataReader to gather data from an Access Database and populates a label with the created variable.
<asp:Label id="lbl1" runat="server" text="<%# streetNuml %
This works just fine.

I then want to pass the data in 'lbl1" to another page (ReceivingPage.aspx) on a button click using

httpContext.Current.Items.Add( "StreetNumu", lbl1.text)
Server.Transfer("ReceivingPage.aspx")

and populate a text box

textbox1.text = HttpContext.Current.Items( "StreetNum" )

but it does work. Blank textbox.

Any help or a solution would be greatly appreciated. Thanks DylanTry using the Server.Transfer method overload that preserves the form variables.

Server.Transfer("blah.aspx", True)
I don't believe this will work even with the preserveForm parameter set to true.

Server.Transfer only preserves the Forms and QueryString collection which is read-only on the server-side. So it is not possible to add something to the collection so that the destination page will be able to reference it.

In this case it might be better to use a simple Response.Redirect with a querystring in order to pass the value.

hope this helps,
sivilian
Thank You for the replies. I've tried both techniques mentioned.

I think the main question, and I've realized this recently, is how to convert a
dynamic variable <%# ...... %> to a static variable that is not associated with the value provided by the database. I think this is possible, but how? Any thoughts.... Thanks again.

Cheers

Dylan

Wednesday, March 21, 2012

Passing variables in .vb page_load event to .aspx file

Hello.
In my page_load event of my web form i check against a database to see if a particular record exists and return a boolean.
How do i get my aspx to check that boolean to determine what to display on the screen.?I would have something like:


// pseudo code

page_load()
{
// get from database

bool doesExist = databasecall();

if (doesExist)
continueSuccessfulDraw();
else
continueUnsuccessfulDraw();
}

Does that help?
You can also do this from within the method that handles the page_load event. One option would be to put a Placeholder control on your .aspx page in the location that you'd want to put whatever it is that is dependent on the boolean you are checking -- and then load the specific controls used for display into the Placeholder.
u need to use web controls
based on the value from the database you can set the visible property true/false

can you give some more details like exactly what you want to display?

Passing XML as parameter to Web page

I must be missing something, because this should be easy to do.
After the user has selected several options on a page, I do a database query
which returns a few records that I want to pass to another page via XML. Ho
w
do I do this?
I typically Response.Redirect around my app, including various parameters.
Do I just include the XML as a parameter as in:
Response.Redirect("page.aspx?" & ds.WriteXML)
That just doesn't seem right.
If you would be so kind as to include both what the sending and receiving
should be doing in any example it would be greatly appreciated!So you have a page, "Page1" which captures some criteria, and then performs
a database query, and passes those results to "Page2" for display.
If it's a particularly small amount of XML, I suppose you could use the
query string, though you want to encode your querystring;
Response.Redirect("page.aspx?" & Server.UrlEncode (ds.WriteXML))
But that seems like a particularly risky way to use a querystring.
It makes more sense to me collect your criteria in Page1, then pass the
actual query parameters to Page2, and have Page2 do the query itself. In
most cases the query params will take much less space to transmit than the
query results. Also it makes Page2 more generally usable [barring special
security concerns].
Another option is to do the query, cache either the query or the result in
the database, and then pass the queryID to Page2. That's a useful approach
for very large complex queries, especially if you want to keep a history of
queries a user has run. I use that for real-estate sites, where the user
can have hundreds of criteria, and the broker needs to know what the
customer is searching for.
/// M
"Steven J. Reed" <StevenJReed@.discussions.microsoft.com> wrote in message
news:61770068-C646-4FE1-80F3-E4C5451DD1E0@.microsoft.com...
> I must be missing something, because this should be easy to do.
> After the user has selected several options on a page, I do a database
query
> which returns a few records that I want to pass to another page via XML.
How
> do I do this?
> I typically Response.Redirect around my app, including various
parameters.
> Do I just include the XML as a parameter as in:
> Response.Redirect("page.aspx?" & ds.WriteXML)
> That just doesn't seem right.
> If you would be so kind as to include both what the sending and receiving
> should be doing in any example it would be greatly appreciated!
Can you use “Session”? You can store XML as DOM object or string in Sess
ion,
and pass Session state to next page, or next of next page. Session is a
popular way to carry data to next page in ASP.NET.
Shaw
"MWells" wrote:

> So you have a page, "Page1" which captures some criteria, and then perform
s
> a database query, and passes those results to "Page2" for display.
> If it's a particularly small amount of XML, I suppose you could use the
> query string, though you want to encode your querystring;
> Response.Redirect("page.aspx?" & Server.UrlEncode (ds.WriteXML))
> But that seems like a particularly risky way to use a querystring.
> It makes more sense to me collect your criteria in Page1, then pass the
> actual query parameters to Page2, and have Page2 do the query itself. In
> most cases the query params will take much less space to transmit than the
> query results. Also it makes Page2 more generally usable [barring special
> security concerns].
> Another option is to do the query, cache either the query or the result in
> the database, and then pass the queryID to Page2. That's a useful approac
h
> for very large complex queries, especially if you want to keep a history o
f
> queries a user has run. I use that for real-estate sites, where the user
> can have hundreds of criteria, and the broker needs to know what the
> customer is searching for.
> /// M
>
> "Steven J. Reed" <StevenJReed@.discussions.microsoft.com> wrote in message
> news:61770068-C646-4FE1-80F3-E4C5451DD1E0@.microsoft.com...
> query
> How
> parameters.
>
>
Thank you both for your responses. I guess you confirmed my suspicions: you
can't pass a stream as the parameter. I will have to pass the text.
I didn't say it in my original post, but there are a couple of reasons I
can't just do the query in Page2. 1) The database query must be kept
independent from the processing due to manipulation of the data and the fact
the data may be coming from multiple sources. 2) Page2 may be on a
different server. 3) Page2 is actually a few different pages, so the desir
e
is that the query done in Page1 passes common data to subsequent pages.
...Steve
"Shaw" wrote:
> Can you use “Session”? You can store XML as DOM object or string in Se
ssion,
> and pass Session state to next page, or next of next page. Session is a
> popular way to carry data to next page in ASP.NET.
> Shaw
>
> "MWells" wrote:
>

Passing XML as parameter to Web page

I must be missing something, because this should be easy to do.

After the user has selected several options on a page, I do a database query
which returns a few records that I want to pass to another page via XML. How
do I do this?

I typically Response.Redirect around my app, including various parameters.
Do I just include the XML as a parameter as in:
Response.Redirect("page.aspx?" & ds.WriteXML)

That just doesn't seem right.

If you would be so kind as to include both what the sending and receiving
should be doing in any example it would be greatly appreciated!So you have a page, "Page1" which captures some criteria, and then performs
a database query, and passes those results to "Page2" for display.

If it's a particularly small amount of XML, I suppose you could use the
query string, though you want to encode your querystring;

Response.Redirect("page.aspx?" & Server.UrlEncode (ds.WriteXML))

But that seems like a particularly risky way to use a querystring.

It makes more sense to me collect your criteria in Page1, then pass the
actual query parameters to Page2, and have Page2 do the query itself. In
most cases the query params will take much less space to transmit than the
query results. Also it makes Page2 more generally usable [barring special
security concerns].

Another option is to do the query, cache either the query or the result in
the database, and then pass the queryID to Page2. That's a useful approach
for very large complex queries, especially if you want to keep a history of
queries a user has run. I use that for real-estate sites, where the user
can have hundreds of criteria, and the broker needs to know what the
customer is searching for.

/// M

"Steven J. Reed" <StevenJReed@.discussions.microsoft.com> wrote in message
news:61770068-C646-4FE1-80F3-E4C5451DD1E0@.microsoft.com...
> I must be missing something, because this should be easy to do.
> After the user has selected several options on a page, I do a database
query
> which returns a few records that I want to pass to another page via XML.
How
> do I do this?
> I typically Response.Redirect around my app, including various
parameters.
> Do I just include the XML as a parameter as in:
> Response.Redirect("page.aspx?" & ds.WriteXML)
> That just doesn't seem right.
> If you would be so kind as to include both what the sending and receiving
> should be doing in any example it would be greatly appreciated!
Can you use "Session"? You can store XML as DOM object or string in Session,
and pass Session state to next page, or next of next page. Session is a
popular way to carry data to next page in ASP.NET.

Shaw

"MWells" wrote:

> So you have a page, "Page1" which captures some criteria, and then performs
> a database query, and passes those results to "Page2" for display.
> If it's a particularly small amount of XML, I suppose you could use the
> query string, though you want to encode your querystring;
> Response.Redirect("page.aspx?" & Server.UrlEncode (ds.WriteXML))
> But that seems like a particularly risky way to use a querystring.
> It makes more sense to me collect your criteria in Page1, then pass the
> actual query parameters to Page2, and have Page2 do the query itself. In
> most cases the query params will take much less space to transmit than the
> query results. Also it makes Page2 more generally usable [barring special
> security concerns].
> Another option is to do the query, cache either the query or the result in
> the database, and then pass the queryID to Page2. That's a useful approach
> for very large complex queries, especially if you want to keep a history of
> queries a user has run. I use that for real-estate sites, where the user
> can have hundreds of criteria, and the broker needs to know what the
> customer is searching for.
> /// M
>
> "Steven J. Reed" <StevenJReed@.discussions.microsoft.com> wrote in message
> news:61770068-C646-4FE1-80F3-E4C5451DD1E0@.microsoft.com...
> > I must be missing something, because this should be easy to do.
> > After the user has selected several options on a page, I do a database
> query
> > which returns a few records that I want to pass to another page via XML.
> How
> > do I do this?
> > I typically Response.Redirect around my app, including various
> parameters.
> > Do I just include the XML as a parameter as in:
> > Response.Redirect("page.aspx?" & ds.WriteXML)
> > That just doesn't seem right.
> > If you would be so kind as to include both what the sending and receiving
> > should be doing in any example it would be greatly appreciated!
>
Thank you both for your responses. I guess you confirmed my suspicions: you
can't pass a stream as the parameter. I will have to pass the text.

I didn't say it in my original post, but there are a couple of reasons I
can't just do the query in Page2. 1) The database query must be kept
independent from the processing due to manipulation of the data and the fact
the data may be coming from multiple sources. 2) Page2 may be on a
different server. 3) Page2 is actually a few different pages, so the desire
is that the query done in Page1 passes common data to subsequent pages.

...Steve

"Shaw" wrote:

> Can you use "Session"? You can store XML as DOM object or string in Session,
> and pass Session state to next page, or next of next page. Session is a
> popular way to carry data to next page in ASP.NET.
> Shaw
>
> "MWells" wrote:
> > So you have a page, "Page1" which captures some criteria, and then performs
> > a database query, and passes those results to "Page2" for display.
> > If it's a particularly small amount of XML, I suppose you could use the
> > query string, though you want to encode your querystring;
> > Response.Redirect("page.aspx?" & Server.UrlEncode (ds.WriteXML))
> > But that seems like a particularly risky way to use a querystring.
> > It makes more sense to me collect your criteria in Page1, then pass the
> > actual query parameters to Page2, and have Page2 do the query itself. In
> > most cases the query params will take much less space to transmit than the
> > query results. Also it makes Page2 more generally usable [barring special
> > security concerns].
> > Another option is to do the query, cache either the query or the result in
> > the database, and then pass the queryID to Page2. That's a useful approach
> > for very large complex queries, especially if you want to keep a history of
> > queries a user has run. I use that for real-estate sites, where the user
> > can have hundreds of criteria, and the broker needs to know what the
> > customer is searching for.
> > /// M
> > "Steven J. Reed" <StevenJReed@.discussions.microsoft.com> wrote in message
> > news:61770068-C646-4FE1-80F3-E4C5451DD1E0@.microsoft.com...
> > > I must be missing something, because this should be easy to do.
> > > > After the user has selected several options on a page, I do a database
> > query
> > > which returns a few records that I want to pass to another page via XML.
> > How
> > > do I do this?
> > > > I typically Response.Redirect around my app, including various
> > parameters.
> > > Do I just include the XML as a parameter as in:
> > > Response.Redirect("page.aspx?" & ds.WriteXML)
> > > > That just doesn't seem right.
> > > > If you would be so kind as to include both what the sending and receiving
> > > should be doing in any example it would be greatly appreciated!

Passsing a connection object

I have a class that creates a connection to the database. When I call this object from my aspx code behind to get a connection to the database I get an error.
Object reference not set to an instance of an object.
How can I pass a connction object back from a class to a aspx code behind.pls post some code so that we might see the problem ...
if an object is not marked as Shared, you need to instantiate it before calling any of its methods.

based on your error you may have something like this:

dim oConn as MyConnectionObject
dim something as string
something = oConn.GetConnString

this will fail

you need

dim oConn asNew MyConnectionObject
dim something as string
something = oConn.GetConnString

Friday, March 16, 2012

Password appearing as blank

All

When I retieve the users password into a textbox
(password textmode) from the database nothing appears, am
I doing something mad?

ThanksThis is done for security reasons. If you set the value of a textbox in
password mode, it will not show anything.

The reason is, it would have to appear in the plain text in the HTML - and
this would be a security risk, as anyone could just look at it, or intercept
it.

"yop" <yop@.oceanfree.net> wrote in message
news:0bed01c36bc8$b34439d0$a401280a@.phx.gbl...
> All
> When I retieve the users password into a textbox
> (password textmode) from the database nothing appears, am
> I doing something mad?
> Thanks
This is done for security reasons. If you set the value of a textbox in
password mode, it will not show anything.

The reason is, it would have to appear in the plain text in the HTML - and
this would be a security risk, as anyone could just look at it, or intercept
it.

"yop" <yop@.oceanfree.net> wrote in message
news:0bed01c36bc8$b34439d0$a401280a@.phx.gbl...
> All
> When I retieve the users password into a textbox
> (password textmode) from the database nothing appears, am
> I doing something mad?
> Thanks
How important that the actual password be in there? You could emit client
side script to set the value there - except set it to a * for every actual
letter. That will basically show the length. If the user tries to edit it -
then blank the whole thing out.

"Yop" <yop@.oceanfree.net> wrote in message
news:056c01c36bd5$708a1710$a001280a@.phx.gbl...
> Marina
> Never thought of that, what work around would people
> suggest or do?
>
> >--Original Message--
> >This is done for security reasons. If you set the value
> of a textbox in
> >password mode, it will not show anything.
> >The reason is, it would have to appear in the plain text
> in the HTML - and
> >this would be a security risk, as anyone could just look
> at it, or intercept
> >it.
> >"yop" <yop@.oceanfree.net> wrote in message
> >news:0bed01c36bc8$b34439d0$a401280a@.phx.gbl...
> >> All
> >>
> >> When I retieve the users password into a textbox
> >> (password textmode) from the database nothing appears,
> am
> >> I doing something mad?
> >>
> >> Thanks
> >.
That is true, nah not overly important, just for a user
admin screen for the administrator only

>--Original Message--
>How important that the actual password be in there? You
could emit client
>side script to set the value there - except set it to a
* for every actual
>letter. That will basically show the length. If the user
tries to edit it -
>then blank the whole thing out.
>"Yop" <yop@.oceanfree.net> wrote in message
>news:056c01c36bd5$708a1710$a001280a@.phx.gbl...
>> Marina
>>
>> Never thought of that, what work around would people
>> suggest or do?
>>
>>
>> >--Original Message--
>> >This is done for security reasons. If you set the
value
>> of a textbox in
>> >password mode, it will not show anything.
>>> >The reason is, it would have to appear in the plain
text
>> in the HTML - and
>> >this would be a security risk, as anyone could just
look
>> at it, or intercept
>> >it.
>>> >"yop" <yop@.oceanfree.net> wrote in message
>> >news:0bed01c36bc8$b34439d0$a401280a@.phx.gbl...
>> >> All
>> >>
>> >> When I retieve the users password into a textbox
>> >> (password textmode) from the database nothing
appears,
>> am
>> >> I doing something mad?
>> >>
>> >> Thanks
>>>> >.
>>
>.
You really shouldn't be storing clear text passwords anyway.. you should
create a message digest based on what they typed in and save that..

Another plus, your admins would not be able to see a user password, only
reset it to something else (which is ideal)..

"yop" <yop@.oceanfree.net> wrote in message
news:010101c36be3$daab6640$a101280a@.phx.gbl...
> That is true, nah not overly important, just for a user
> admin screen for the administrator only
>
> >--Original Message--
> >How important that the actual password be in there? You
> could emit client
> >side script to set the value there - except set it to a
> * for every actual
> >letter. That will basically show the length. If the user
> tries to edit it -
> >then blank the whole thing out.
> >"Yop" <yop@.oceanfree.net> wrote in message
> >news:056c01c36bd5$708a1710$a001280a@.phx.gbl...
> >> Marina
> >>
> >> Never thought of that, what work around would people
> >> suggest or do?
> >>
> >>
> >> >--Original Message--
> >> >This is done for security reasons. If you set the
> value
> >> of a textbox in
> >> >password mode, it will not show anything.
> >> >> >The reason is, it would have to appear in the plain
> text
> >> in the HTML - and
> >> >this would be a security risk, as anyone could just
> look
> >> at it, or intercept
> >> >it.
> >> >> >"yop" <yop@.oceanfree.net> wrote in message
> >> >news:0bed01c36bc8$b34439d0$a401280a@.phx.gbl...
> >> >> All
> >> >>
> >> >> When I retieve the users password into a textbox
> >> >> (password textmode) from the database nothing
> appears,
> >> am
> >> >> I doing something mad?
> >> >>
> >> >> Thanks
> >> >> >> >.
> >> >.
That is what I will do, should have coped that is what
they are doing in Windows!

Thanks all

>--Original Message--
>You really shouldn't be storing clear text passwords
anyway.. you should
>create a message digest based on what they typed in and
save that..
>Another plus, your admins would not be able to see a
user password, only
>reset it to something else (which is ideal)..
>"yop" <yop@.oceanfree.net> wrote in message
>news:010101c36be3$daab6640$a101280a@.phx.gbl...
>> That is true, nah not overly important, just for a user
>> admin screen for the administrator only
>>
>>
>> >--Original Message--
>> >How important that the actual password be in there?
You
>> could emit client
>> >side script to set the value there - except set it to
a
>> * for every actual
>> >letter. That will basically show the length. If the
user
>> tries to edit it -
>> >then blank the whole thing out.
>>> >"Yop" <yop@.oceanfree.net> wrote in message
>> >news:056c01c36bd5$708a1710$a001280a@.phx.gbl...
>> >> Marina
>> >>
>> >> Never thought of that, what work around would people
>> >> suggest or do?
>> >>
>> >>
>> >> >--Original Message--
>> >> >This is done for security reasons. If you set the
>> value
>> >> of a textbox in
>> >> >password mode, it will not show anything.
>> >>> >> >The reason is, it would have to appear in the plain
>> text
>> >> in the HTML - and
>> >> >this would be a security risk, as anyone could just
>> look
>> >> at it, or intercept
>> >> >it.
>> >>> >> >"yop" <yop@.oceanfree.net> wrote in message
>> >> >news:0bed01c36bc8$b34439d0$a401280a@.phx.gbl...
>> >> >> All
>> >> >>
>> >> >> When I retieve the users password into a textbox
>> >> >> (password textmode) from the database nothing
>> appears,
>> >> am
>> >> >> I doing something mad?
>> >> >>
>> >> >> Thanks
>> >>> >>> >> >.
>> >>>>> >.
>>
>.

Password Field not getting populated from Database

I have a web form password field that needs to show the password value as "****" from tha database. It seems that it all it shows is blank but when I change it to a regular text fiels it works. All I do is change the "TEXTMODE" property nothing more.

Any HelpHi,

ASP.NET TexBox just doesn't write out the text when it is in password mode, it's just security precaution. However if you absolutely need such feature, you can wrap it simply in a custom control.

C#


using System;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Joteke.Controls
{
public class MyTextBox : TextBox
{
protected override void AddAttributesToRender(HtmlTextWriter writer)
{
base.AddAttributesToRender (writer);
if(this.TextMode == TextBoxMode.Password)
{
string text=this.Text;
if(text.Length > 0)
writer.AddAttribute(HtmlTextWriterAttribute.Value,text);
}
}

}
}

VB (translated from C# with a tool)


Imports System
Imports System.Web.UI
Imports System.Web.UI.WebControls

Namespace Joteke.Controls

Public Class MyTextBox
Inherits TextBox

Protected Overrides Sub AddAttributesToRender(writer As HtmlTextWriter)
MyBase.AddAttributesToRender(writer)

If Me.TextMode = TextBoxMode.Password Then
Dim [text] As String = Me.Text

If [text].Length > 0 Then
writer.AddAttribute(HtmlTextWriterAttribute.Value, [text])
End If

End If

End Sub 'AddAttributesToRender
End Class 'MyTextBox
End Namespace 'Joteke.Controls


I don't mind that security feature the only problem is that when you go to update a user the password field is blank and if you made no change to the password field then it updates as "" instead of the previous value.

Any solution for this then ?
Well, the password is in the HTML after postback (rendered along with the HTML), that's the only part.

As I said, previous control allows you to prepopulate TextBox even in password mode.
FYI: I blogged this one here.

http://blogs.aspadvice.com/joteke/archive/2005/02/03/2531.aspx

There's also provided the shortcut solution, that is just adding the value to the Attributes collection when you wouldn't need to write a custom control.