Showing posts with label webpage. Show all posts
Showing posts with label webpage. Show all posts

Thursday, March 29, 2012

Passing Values Between web forms pages

i am trying to implement passing values from my login webpage to another. but i get an error of "Specified cast is not valid."

i followed the program logic and I cant find the error that the debugger says that it is in the casting. I am following the example provided by Microsoft in
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconpassingservercontrolvaluesbetweenpages.asp

next, it is the code behind of both forms

1st webform

<---login.aspx---
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

End Sub
Public ReadOnly Property UserId() As String
Get
Return Trim(txtUser.Text)
End Get
End Property

Private Sub lnkLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lnkLogin.Click

Server.Transfer("secondForm.aspx")

end sub

<----secondForm.aspx---
Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Web

Imports System.Web.Security
Imports System.Web.UI

Public Class secondForm

Inherits System.Web.UI.Page

Public userLogin As login

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim blnAddinProgress As Boolean

Dim strUsername As String

If Not IsPostBack() Then

userLogin = CType(Context.Handler, login)

strUsername = userLogin.UserId

<-----
The error that i got from the debugger is "Specified cast is not valid."

following this message, Do i have to change the casting or is there another error or piece of code that i am forgetting.

thanks in advanceYou might try the similar technique documented in this topic:

Passing Values Between Web Forms Pages
HI! the link that you provided me is the one that i used.

If you see the structure of the code is pretty simmilar to the one of the link. Do you know about other option?
the error could be related to I am using Forms authentications?

thank you very much for your help
>HI! the link that you provided me is the one that i used.

Ok. The URL that you provided is not the same as the one for the other article, so I was a little confused.

Here's a question: what kind of control is lnkLogin in your login page? It should be a LinkButton or just Button (not a Hyperlink).

So, assuming that you're using a LinkButton, the bad news is that I cannot reproduce your error. I had to add a line (which you probably have). This is what my target page code looks like:

 Public userLogin As login
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles MyBase.Load
Dim blnAddinProgress As Boolean
Dim strUsername As String
If Not IsPostBack() Then
userLogin = CType(Context.Handler, login)
strUsername = userLogin.UserId
Response.Write(strUsername)
End If
End Sub

Wednesday, March 21, 2012

Passing Variables to another webpage

Pls. help!!!!!!! jas started in ASP.NET.

How Can I Pass the text in a textbox to another webpage?
Thanks in advance . . .You have a number of ways in .NET to pass information but the whole point of .NET is that controls (textboxes) are programmatically accessible so in your postback you basically just say
sString = textbox1.text

However, if you're wanting to pass it to a completely different page, then you'd need to redirect and use either querystring, session or global module (type properties0 to hold the data.

eg

Sub onButtonClick (...)
sString = textbox1.text
response.redirect("myNewPage.aspx?ss=" & sString & "")

End sub
Take a look at the Global.asax File.

//-- define the vaiable

public class Global : System.Web.HttpApplication
{

//...

public static int anwStatus;

//...

}

//-- use the variable, e.g.
Global.anwStatus = 1;

by
Andreas

Passing variables vs session variable

what is the advantage of passing the variable in the url vs storing the variable in a session variable and retrieving it in the second webpage you are accessing?

The variable that you will pass using the QueryString will be visible to the user hence not secured. The value that you put in the Session is not available to the user as it is on the server side and hence more secured.


performance wise does it matter?


Just my 2 cents...

I remember in college the professors would always harp upon using the Session responsibly. Most of the professors were older and came from backgrounds where memory was used sparingly. So, if you were cramming loads of data into the Session (back in the day), you'd maybe begin to experience some bad effects because of it. Accordingly it was advised to use the Session sparingly.

However, it seems to me that things have changed a little. We have more memory and it's faster than ever; the average joe-blow user has more bandwidth than ever. Consequently I don't think people worry about using the Session too much as much.


Yes, performance wise, session variables take up memory on the server so using too many sessions can affect the overall performance of the site. I use them a lot and haven't seen too much of a performance issue, you must have to use a lot of them to affect memory. Or maybe sticking arrays into sessions would start to affect things. Good luck, Mike


there are a few ways of passing variables around:

Single page Postbacks:

1) Use ViewState. It's simple, encrypted. Only problem is too much will slow the clients computer down

2) Use hidden <asp:labels />. Pretty much the same approach as the veiw state.


Navigating from page-> page

1) Query String. Yea, they might see some ID's at the top.

2) you can "Submit" to a new page with ASP.NET 2.0, which allows you to use values from your original page.

3) You can use session. But I would advise against it. Session variables should be used to house things that are important for the user, like: ID, UserName, etc. I would never want to see a dataTable, Array, etc. stored in the session.


Friday, March 16, 2012

password field cant be preloaded

Hi,

I have a quick question.

I have a webpage allow user to modify his/her information. When I
generate the form, I want to pre-load the information to the
TextBoxes. But for the password (and confirm password) textbox, the
text can't be loaded (the TextBoxes are empty, no "dot" in them). I
checked inside Page_Load the text is loaded, but when the page is
render, the data is flushed.

I read some ASP code that in ASP this won't happen, you just do:

<input type="password" name="vcPassword" value="<%=vcPassword%>"
Please Help

Homa WongYou're not supposed to set the text of a password field from the server
because it's unsecure. That's why it didn't show up; it's prevented as a
security precaution. (The password would be plain text to anybody who views
the source of the page.)

However there is a workaround if you are willing to accept this risk.
Here's the simplest example I've seen:

MyPWTextBox.Attributes.Add("value", strPassWord)

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net
Hire top-notch developers at http://www.able-consulting.com

"Homa" <homaneag@.yahoo.com> wrote in message
news:a9a6fc0b.0310201646.1763edf0@.posting.google.c om...
> Hi,
> I have a quick question.
> I have a webpage allow user to modify his/her information. When I
> generate the form, I want to pre-load the information to the
> TextBoxes. But for the password (and confirm password) textbox, the
> text can't be loaded (the TextBoxes are empty, no "dot" in them). I
> checked inside Page_Load the text is loaded, but when the page is
> render, the data is flushed.
> I read some ASP code that in ASP this won't happen, you just do:
> <input type="password" name="vcPassword" value="<%=vcPassword%>">
>
> Please Help
> Homa Wong
You're not supposed to set the text of a password field from the server
because it's unsecure. That's why it didn't show up; it's prevented as a
security precaution. (The password would be plain text to anybody who views
the source of the page.)

However there is a workaround if you are willing to accept this risk.
Here's the simplest example I've seen:

MyPWTextBox.Attributes.Add("value", strPassWord)

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net
Hire top-notch developers at http://www.able-consulting.com

"Homa" <homaneag@.yahoo.com> wrote in message
news:a9a6fc0b.0310201646.1763edf0@.posting.google.c om...
> Hi,
> I have a quick question.
> I have a webpage allow user to modify his/her information. When I
> generate the form, I want to pre-load the information to the
> TextBoxes. But for the password (and confirm password) textbox, the
> text can't be loaded (the TextBoxes are empty, no "dot" in them). I
> checked inside Page_Load the text is loaded, but when the page is
> render, the data is flushed.
> I read some ASP code that in ASP this won't happen, you just do:
> <input type="password" name="vcPassword" value="<%=vcPassword%>">
>
> Please Help
> Homa Wong
It's a security issue. If you want your applications to be secure you should
only store hashed password values so you will never be able to know the
original password. And in any case you should not be sending passwords to
anybody, not even the original user.

Jerry

"Homa" <homaneag@.yahoo.com> wrote in message
news:a9a6fc0b.0310201646.1763edf0@.posting.google.c om...
> Hi,
> I have a quick question.
> I have a webpage allow user to modify his/her information. When I
> generate the form, I want to pre-load the information to the
> TextBoxes. But for the password (and confirm password) textbox, the
> text can't be loaded (the TextBoxes are empty, no "dot" in them). I
> checked inside Page_Load the text is loaded, but when the page is
> render, the data is flushed.
> I read some ASP code that in ASP this won't happen, you just do:
> <input type="password" name="vcPassword" value="<%=vcPassword%>">
>
> Please Help
> Homa Wong
It's a security issue. If you want your applications to be secure you should
only store hashed password values so you will never be able to know the
original password. And in any case you should not be sending passwords to
anybody, not even the original user.

Jerry

"Homa" <homaneag@.yahoo.com> wrote in message
news:a9a6fc0b.0310201646.1763edf0@.posting.google.c om...
> Hi,
> I have a quick question.
> I have a webpage allow user to modify his/her information. When I
> generate the form, I want to pre-load the information to the
> TextBoxes. But for the password (and confirm password) textbox, the
> text can't be loaded (the TextBoxes are empty, no "dot" in them). I
> checked inside Page_Load the text is loaded, but when the page is
> render, the data is flushed.
> I read some ASP code that in ASP this won't happen, you just do:
> <input type="password" name="vcPassword" value="<%=vcPassword%>">
>
> Please Help
> Homa Wong