Thursday, March 29, 2012
Passing values between pages with MasterPages
conclusions, can you please tell me if I am right:
I have 2 aspx pages both with the same master page and I wish to pass
values from one to the other.
1. The postbackurl method doesn't seem to work with master pages. If I
take away the master pages it works.
2. The server.transfer method also doesn't work if I try to acess the
values via Request.Form or PreviousPage.FindControl. Again if I take
away the master pages it works.
3. My only option if I don't want to use the querystring to pass the
values (i.e. response.redirect) is to use a method which stores the
values in the server's RAM. e.g use Context.Items in conjunction with
Server.Transfer. This works with MasterPages but has the downfall of
the server's RAM now being used.
Please tell me if I am wrong or if there is no way of using cross page
posting or server.transfer for passing values from one aspx page with a
masterpage to another with the same masterpage without storing the
values in RAM?
Kind regards,
Steve."Steve" wrote:
> I have 2 aspx pages both with the same master page and I wish to pass
> values from one to the other.
Try using session variables, which should persist across page requests at a
user level:
1)
Session("SettingName") = strSettingValue
2)
strSettingValue = CStr(Session("SettingName"))
Passing values between pages with MasterPages
conclusions, can you please tell me if I am right:
I have 2 aspx pages both with the same master page and I wish to pass
values from one to the other.
1. The postbackurl method doesn't seem to work with master pages. If I
take away the master pages it works.
2. The server.transfer method also doesn't work if I try to acess the
values via Request.Form or PreviousPage.FindControl. Again if I take
away the master pages it works.
3. My only option if I don't want to use the querystring to pass the
values (i.e. response.redirect) is to use a method which stores the
values in the server's RAM. e.g use Context.Items in conjunction with
Server.Transfer. This works with MasterPages but has the downfall of
the server's RAM now being used.
Please tell me if I am wrong or if there is no way of using cross page
posting or server.transfer for passing values from one aspx page with a
masterpage to another with the same masterpage without storing the
values in RAM?
Kind regards,
Steve."Steve" wrote:
Quote:
Originally Posted by
I have 2 aspx pages both with the same master page and I wish to pass
values from one to the other.
Try using session variables, which should persist across page requests at a
user level:
1)
Session("SettingName") = strSettingValue
2)
strSettingValue = CStr(Session("SettingName"))
Passing Values Between web forms pages
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
Monday, March 26, 2012
passing values with request.redirect
The code is:(first page login.aspx)
<%@dotnet.itags.org. Page Language="VB" %>
<%@dotnet.itags.org. import Namespace="System.Web" %>
<script runat="server"
sub submit(Source as object, e as eventargs)
Dim xml
xml=Server.CreateObject("Microsoft.XMLDOM")
xml.async=false
xml.load(Server.Mappath("users.xml"))
Dim user, password
user = xml.documentElement.childNodes(0).text
password = xml.documentElement.childNodes(1).text
if(user = UserName.text) then
response.redirect("welcome.aspx")
else
response.write("relogin please")
end if
end sub
sub reset(Source as object, e as eventargs)
UserName.text=""
pass.value=""
end sub
</script>
<html>
<head>
</head>
<body bgcolor="#ffffff">
<form action="Welcome.aspx" method="get" runat="server">
<p align="center">
Login Page
</p>
<p align="center">
Username:
<asp:TextBox id="UserName" runat="server"></asp:TextBox>
</p>
<p align="center">
Password: <input id="pass" type="password" name="pass" runat="server" />
</p>
<p align="center">
<input type="submit" value="Submit" runat="server" onserverclick="submit" /> <asp:Button id="Button2" onclick="reset" runat="server" Text="Reset"></asp:Button>
</p>
<p align="center">
Register
</p>
<p align="center">
</p>
<!-- Insert content here -->
</form>
</body>
</html
***************************************************************
Second Page: (welcome.aspx)
<%@dotnet.itags.org. Page Language="VB" %>
<script runat="server"
sub page_load
Response.Write("<h3><center>Welcome</h3></center>")
Response.Write(Request.QueryString("UserName"))
end sub
</script>
<html>
<head>
</head>
<body>
<form runat="server">
<!-- Insert content here -->
</form>
</body>
</html
It shows Welcome but does not show the username.On your submit sub where you redirect to the welcome page: Response.Redirect("welcome.aspx"), yea, there's nothing in the QueryString. QueryString values are appended after the url. A possible fix would be to re-write that line to say: Response.Redirect("welcome.aspx?UserName="&user)
Try adding the a querystring to your Response.Redirect call on the first page. For example:
Response.Redirect("welcome.aspx?UserName=" & user)
You know that .NET has already done what you're trying to do don't you?
Search the forum for Login Page and/or User.Identity.Name and you'll find some examples.
Friday, March 16, 2012
password field: Syntax error in INSERT INTO statement.
I am trying to execute ADO.NET INSERT statement where one of the
fields
is coming from a password HTML control. When I access the text with
password.Value and print with Response.Write so as to check that it
is working correctly it displays just fine. However, whenever I
include the password field in one of the SQL INSERT statement's
fields I get the following error:
Exception Details: System.Data.OleDb.OleDbException: Syntax error in
INSERT INTO statement.
Line 85: cmd.ExecuteNonQuery();
When I delete the password field from the insert statement things work
fine (so the problem is no longer related to NTFS file permissions).
Any ideas on how to solve this problem would be greatly appreciated.
Best Regards,
NeilNeil, it's difficult to pinpoint your problem without seeing some code; but
here are a few ideas to get you started;
If you're using a WebControls textbox (and not an HtmlControls input box),
then the correct accessor would be something like txtPassword.Text
Triple-check your SQL. Try modifying it so that the value you're entering
in the textbox is manually assigned to the SqlParam (or embedded in your sql
string, etc). That will help you debug your SQL, your schema, etc while
removing the textbox from the equation.
Try very simple passwords, e.g. "a". If that succeeds, you might be having
a problem with unescaped apostrophes or something similar.
If you can, display the generated Sql in a Trace.Write or a Response.Write,
and copy/paste it into your Sql tool to test it manually.
Best of luck,
/// M
"Neil Zanella" <nzanella@.gmail.com> wrote in message
news:1ac72686.0501221942.349922c2@.posting.google.com...
> Hello,
> I am trying to execute ADO.NET INSERT statement where one of the
> fields
> is coming from a password HTML control. When I access the text with
> password.Value and print with Response.Write so as to check that it
> is working correctly it displays just fine. However, whenever I
> include the password field in one of the SQL INSERT statement's
> fields I get the following error:
> Exception Details: System.Data.OleDb.OleDbException: Syntax error in
> INSERT INTO statement.
> Line 85: cmd.ExecuteNonQuery();
> When I delete the password field from the insert statement things work
> fine (so the problem is no longer related to NTFS file permissions).
> Any ideas on how to solve this problem would be greatly appreciated.
> Best Regards,
> Neil
Hello,
Thank you for your reply. I have already tried everything
you suggested. I also had a problem with calling
Response.Write to debug my SQL query as
whenever I use it the parameter holders
which begin with @. are not substituted
when I call Response.Write (is there
some special method I can call on
OleDbCommand to print the actual
query with the parameters
substituted in?)
Anyways, here was my problem: as strange as
it may sound, I renamed a field called "password"
in MS Access to "foo" and did the same in the
query contained in the code. I don't know how
come but that fixed it. Is there something
special about calling a table's field
"password" in MS Access which
causes the query error I was
experiencing'
Thanks,
Neil
It might be a reserved word in Access. In Sql Server you can use most
reserved words as column names, but you reference them in your sql using
[brackets].
Since you've identified it as an Access or .NET->Access issue, I'd also try
seaching some of those newsgroups.
<nzanella@.gmail.com> wrote in message
news:1106607939.521494.187670@.f14g2000cwb.googlegroups.com...
> Hello,
> Thank you for your reply. I have already tried everything
> you suggested. I also had a problem with calling
> Response.Write to debug my SQL query as
> whenever I use it the parameter holders
> which begin with @. are not substituted
> when I call Response.Write (is there
> some special method I can call on
> OleDbCommand to print the actual
> query with the parameters
> substituted in?)
> Anyways, here was my problem: as strange as
> it may sound, I renamed a field called "password"
> in MS Access to "foo" and did the same in the
> query contained in the code. I don't know how
> come but that fixed it. Is there something
> special about calling a table's field
> "password" in MS Access which
> causes the query error I was
> experiencing'
> Thanks,
> Neil
>
password field: Syntax error in INSERT INTO statement.
I am trying to execute ADO.NET INSERT statement where one of the
fields
is coming from a password HTML control. When I access the text with
password.Value and print with Response.Write so as to check that it
is working correctly it displays just fine. However, whenever I
include the password field in one of the SQL INSERT statement's
fields I get the following error:
Exception Details: System.Data.OleDb.OleDbException: Syntax error in
INSERT INTO statement.
Line 85: cmd.ExecuteNonQuery();
When I delete the password field from the insert statement things work
fine (so the problem is no longer related to NTFS file permissions).
Any ideas on how to solve this problem would be greatly appreciated.
Best Regards,
NeilNeil, it's difficult to pinpoint your problem without seeing some code; but
here are a few ideas to get you started;
If you're using a WebControls textbox (and not an HtmlControls input box),
then the correct accessor would be something like txtPassword.Text
Triple-check your SQL. Try modifying it so that the value you're entering
in the textbox is manually assigned to the SqlParam (or embedded in your sql
string, etc). That will help you debug your SQL, your schema, etc while
removing the textbox from the equation.
Try very simple passwords, e.g. "a". If that succeeds, you might be having
a problem with unescaped apostrophes or something similar.
If you can, display the generated Sql in a Trace.Write or a Response.Write,
and copy/paste it into your Sql tool to test it manually.
Best of luck,
/// M
"Neil Zanella" <nzanella@.gmail.com> wrote in message
news:1ac72686.0501221942.349922c2@.posting.google.c om...
> Hello,
> I am trying to execute ADO.NET INSERT statement where one of the
> fields
> is coming from a password HTML control. When I access the text with
> password.Value and print with Response.Write so as to check that it
> is working correctly it displays just fine. However, whenever I
> include the password field in one of the SQL INSERT statement's
> fields I get the following error:
> Exception Details: System.Data.OleDb.OleDbException: Syntax error in
> INSERT INTO statement.
> Line 85: cmd.ExecuteNonQuery();
> When I delete the password field from the insert statement things work
> fine (so the problem is no longer related to NTFS file permissions).
> Any ideas on how to solve this problem would be greatly appreciated.
> Best Regards,
> Neil
Hello,
Thank you for your reply. I have already tried everything
you suggested. I also had a problem with calling
Response.Write to debug my SQL query as
whenever I use it the parameter holders
which begin with @. are not substituted
when I call Response.Write (is there
some special method I can call on
OleDbCommand to print the actual
query with the parameters
substituted in?)
Anyways, here was my problem: as strange as
it may sound, I renamed a field called "password"
in MS Access to "foo" and did the same in the
query contained in the code. I don't know how
come but that fixed it. Is there something
special about calling a table's field
"password" in MS Access which
causes the query error I was
experiencing??
Thanks,
Neil
It might be a reserved word in Access. In Sql Server you can use most
reserved words as column names, but you reference them in your sql using
[brackets].
Since you've identified it as an Access or .NET->Access issue, I'd also try
seaching some of those newsgroups.
<nzanella@.gmail.com> wrote in message
news:1106607939.521494.187670@.f14g2000cwb.googlegr oups.com...
> Hello,
> Thank you for your reply. I have already tried everything
> you suggested. I also had a problem with calling
> Response.Write to debug my SQL query as
> whenever I use it the parameter holders
> which begin with @. are not substituted
> when I call Response.Write (is there
> some special method I can call on
> OleDbCommand to print the actual
> query with the parameters
> substituted in?)
> Anyways, here was my problem: as strange as
> it may sound, I renamed a field called "password"
> in MS Access to "foo" and did the same in the
> query contained in the code. I don't know how
> come but that fixed it. Is there something
> special about calling a table's field
> "password" in MS Access which
> causes the query error I was
> experiencing??
> Thanks,
> Neil
Password length minimum: 7. Non-alphanumeric characters required: 1.
this error. Microsoft Security Policy requires something nonsense I think. I
never think a password like "75256asdf!^+%&" this. How can I use normal
passwords which users demand what their hearth say as a password.: 1.re:
> How can I use normal passwords which users demand what their hearth say as a passw
ord.
In the <providers section of web.config :
minRequiredPasswordLength="1"
minRequiredNonalphanumericCharacters="0"
See :
http://msdn2.microsoft.com/en-us/li.../>
_properties(vs.80).aspx
Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en espaol : http://asp.net.do/foros/
===================================
"Yasin Cepeci" <cepeci@.gmail.com> wrote in message news:um4HyLCiHHA.3452@.TK2MSFTNGP04.phx.g
bl...
> Password length minimum: 7. Non-alphanumeric characters required.I ve take
n this error. Microsoft
> Security Policy requires something nonsense I think. I never think a passw
ord like
> "75256asdf!^+%&" this. How can I use normal passwords which users demand w
hat their hearth say as
> a password.: 1.
>