Showing posts with label figure. Show all posts
Showing posts with label figure. Show all posts

Saturday, March 24, 2012

Passing variables from datagrid to code-behind?

This is a bit embarassing, but I just can't seem to figure it out...
I have a simple datagrid that uses a calendar control to display information by a selected date. One field of the datagrid is a hyperlink column that allows the user to see additional details about each item in a pop-up window.
The pop-up window is another simple datagrid, using a code-behind to look-up the extra information.
The (Access) database uses separate tables for each month of the year (0105, 0205, etc.) and which table we need to read is determined by the selected month of the calendar control.
But I cannot figure out how to pass the month to the code behind to use the correct table in the query for detailed information.
Here is the primary datagrid hyperlink column:
<asp:HyperLinkColumn
DataTextField="Title"
DataNavigateUrlField="ResvNum"
DataNavigateUrlFormatString="javascript: var popWindow=window.open('event-detail.aspx?id={0}', 'popWindow'); popWindow.focus();"
Target="_self"
HeaderText="Title">
</asp:HyperLinkColumn>
[ResvNum is the primary key for each table, Access auto-increment]
And here is the code-behind (minus 'Import' statements):
public class Detail : Inherits System.Web.UI.Page
public eventDetail as DataGrid

private sub Page_Load (sender as object, e as System.EventArgs)
dim _id as String = Request.QueryString("id")
dim strSQL as String = "SELECT [0805].ResvNum, [0805].Dy, [0805].BegTime, [0805].Ending, [0805].EventType, [0805].Title, [0805].Person, Facility.BldgName, Facility.Abbrev " & _
"FROM Facility LEFT JOIN [0805] ON Facility.FacNum = [0805].Room " & _
"WHERE [0805].ResvNum = " & _id & ""
eventDetail.DataSource = getDetail(strSQL)
eventDetail.DataBind()
end sub

private function getDetail (strSQL as string) as oleDbDataReader
dim dtrDetail as oleDbDataReader
dim detailConn as oleDbConnection = new oleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & server.mappath("../TESTDATA/TEST.mdb") & ";")
dim detailCmd as oleDbCommand = new oleDbCommand(strSQL, detailConn)
detailCmd.Connection.Open()
dtrDetail = detailCmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection)
return dtrDetail
end function
end class
This is hard-coded to read the data table for August 2005. It is the [0805] I need to dynamically change depending on the selected date.
How do I pass that date to the code-behind query?
Thanks,
Tinker

You can only send 1 value if you use the datanavigatfield - but you canconstruct your own datanavigaturl and use template columns
<ItemTemplate>
<asp:HyperLink id="linkColumn1" runat="server"Text='<%# DataBinder.Eval(Container,"DataItem.MyDataField") %>'Target=_blank NavigateUrl='<%#"event-detail.aspx?id="& DataBinder.Eval(Container,"DataItem.MyDataField") & "?other_param=" & DataBinder.Eval(Container,"DataItem.MyOtherDataField") %>'>
</asp:HyperLink>
</ItemTemplate>
HTH

uncleb --
Thank you for this, and it makes sense -- but the file identifier is not a dataitem. It is derived from the calendar control as
qryFile = calDate.SelectedDate.ToString("MMyy")
and used in the query as
strSQL = "SELECT ResvNum, Person FROM qryFile"
So I can't pass it as part fo the dataitems collection.
Or -- at least -- I still don't know how to identifiy it to send it on to the code-behind.
If there's a refernce article, please send me off to read it.
Thanks again,


<ItemTemplate>
<asp:HyperLink id="linkColumn1" runat="server"Text='<%# DataBinder.Eval(Container,"DataItem.MyDataField") %>'Target=_blank NavigateUrl='<%#"event-detail.aspx?id="& DataBinder.Eval(Container,"DataItem.MyDataField") & "?qryFile=" &calDate.SelectedDate.ToString("MMyy") %>'>
</asp:HyperLink>
</ItemTemplate>
if the calendar is on the same page and loaded with the right date . Ifnot, I would use a button - then in the click event set the urlstringusing the datagrid datakeyfield and the calDate

HTH

YES! This works!
Thanks for hanging-in and guiding me through this. Appreciate it HUGELY.

Okay, I spoke too soon...
<asp:HyperLink id="linkColumn1" runat="server"
Text = '<%# DataBinder.Eval(Container,"DataItem.Title") %>'
NavigateUrl = '<%# "event-detail.aspx?qryFile = " & calDate.SelectedDate.ToString("MMyy") & "& ?id = "& DataBinder.Eval(Container, "DataItem.ResvNum") %>'
Target = _blank>
</asp:HyperLink>

Does not seem to be passing the second variable to the code behind, regardless of whether I rearrange the variable to make "id" first or second.
In the code-behind, I added:
trace.warn ("Incoming File " & Request.QueryString("qryFile "))
trace.warn ("Incoming ID " & Request.QueryString("id"))

dim _qryFile as String = Request.QueryString("qryFile ")
dim _id as String = Request.QueryString("id")

trace.warn ("Query File " & _qryFile)
trace.warn ("Query ID " & _id)
And these are the results of the trace.warnings:
Incoming File = 0805
Incoming ID =
Query File = 0805
Query ID =

(Reversing the order in which I pass the variables -- putting "id" first -- passes the ID, but not the qryFile date)
What am I doing wrong in the HyperLink NavigateUrl statement?


try..
NavigateUrl = '<%# "event-detail.aspx?qryFile=" &calDate.SelectedDate.ToString("MMyy") & "?id=" &DataBinder.Eval(Container, "DataItem.ResvNum") %>'
I took out an " &" and got rid of some spaces - no spaces in querystrings.



Well, you're still haniging in with me, and I appreciate it.
Didn't work. When I remove the '&' in the navurl, the variables are passed as a single variable, and the trace showsFileID = 0805?id=1769andResvNum=. I did remove all of the blank spaces, however.
I'm not sure what I'm seeing here, but maybe this will help: when the cursor is over the link on the (first page) data grid, the IE status bar shows that the link is
events-detail.aspx?qryFile=0805&?id=1120 -- which is a valid record id (ResvNum) in an existing table, and that LOOKS right to me. But the "id" is still not making it to the code-behind...
I'm kind of at a loss with this, and I'm just not smart enough to see what I'm doing wrong.
If there's anything more I can add to this thread that might help pinpoint my error, let me know?

Sorry , my fault

try..
NavigateUrl = '<%# "event-detail.aspx?qryFile=" &calDate.SelectedDate.ToString("MMyy") & "&id=" &DataBinder.Eval(Container, "DataItem.ResvNum") %>'
there is only one question mark in a querystring- params are seperated by "&"

So was it all just a test to see if I'd finally admit how dumb I am? 8-)
The two "?" was the problem; it is all working. I've been staring at it for three days and didn't see it.
Again, many thanks.

Wednesday, March 21, 2012

passing variables question

Ok, sorry if this is dumb ?, but I'm extremely new to ASP.net. I've used
PHP and am now trying to figure out the best way (or any way) to do this in
ASP.net:
I have a page where the user enters data and clicks a submit button which
redirects to another page. This 2nd page can retrieve all of the POST
variables submitted from the previous page. How is this done in ASP.net?
Thanks!The ASP.NET model is for the first page to handle its own data submission.
It should deal with the data, and then redirect to the next page. That page
then handles all its own data.
If you did want to do what you are describing, you would either need to set
the form to post to the second page to begin with, or you would need to do a
Server.Transfer to the second page.
"melinda" <melinda@.discussions.microsoft.com> wrote in message
news:5033F7C5-5EB7-446E-B145-2B3443C58ECF@.microsoft.com...
> Ok, sorry if this is dumb ?, but I'm extremely new to ASP.net. I've used
> PHP and am now trying to figure out the best way (or any way) to do this
> in
> ASP.net:
> I have a page where the user enters data and clicks a submit button which
> redirects to another page. This 2nd page can retrieve all of the POST
> variables submitted from the previous page. How is this done in ASP.net?
> Thanks!
You can save the values to a a session and redirect the page to the
second page and then read from the session.
Also, this might help:
http://authors.aspalliance.com/kenc/passval.aspx
Shahid
"melinda" <melinda@.discussions.microsoft.com> wrote in message
news:5033F7C5-5EB7-446E-B145-2B3443C58ECF@.microsoft.com...
> Ok, sorry if this is dumb ?, but I'm extremely new to ASP.net. I've used
> PHP and am now trying to figure out the best way (or any way) to do this
> in
> ASP.net:
> I have a page where the user enters data and clicks a submit button which
> redirects to another page. This 2nd page can retrieve all of the POST
> variables submitted from the previous page. How is this done in ASP.net?
> Thanks!
ASP.NET forms by default submit to self.
I generally put my code in the button click server event. Then I redirect
to the next page if all goes well.
John
There are different technique to transfer data from one page to another. The
simple and easy way is to use Session Variable. You can also use QueryString
.
For Session variable, You can save the values to a session and redirect the
destination page and then read the date from the session.
let there are two pages WebForm1.aspx and WebForm2.aspx. on the WebForm1 you
have 2 string variables and u want to access these two variables on 2nd page
U have to do on the Webform1.aspx:
string name = "Irfan";
string age = 30;
Session["anySessionVariableName1"] = name;
Session["anySessionVariableName2"] = age;
Response.Redirect("WebForm2.aspx");
on the WebForm2.aspx, u have to do for retrieving the name and age:
string nm = Session["anySessionVariableName1"].ToString();
string ag = Session["anySessionVariableName2"].ToString();
"melinda" wrote:

> Ok, sorry if this is dumb ?, but I'm extremely new to ASP.net. I've used
> PHP and am now trying to figure out the best way (or any way) to do this i
n
> ASP.net:
> I have a page where the user enters data and clicks a submit button which
> redirects to another page. This 2nd page can retrieve all of the POST
> variables submitted from the previous page. How is this done in ASP.net?
> Thanks!

passing variables question

Ok, sorry if this is dumb ?, but I'm extremely new to ASP.net. I've used
PHP and am now trying to figure out the best way (or any way) to do this in
ASP.net:
I have a page where the user enters data and clicks a submit button which
redirects to another page. This 2nd page can retrieve all of the POST
variables submitted from the previous page. How is this done in ASP.net?
Thanks!The ASP.NET model is for the first page to handle its own data submission.
It should deal with the data, and then redirect to the next page. That page
then handles all its own data.

If you did want to do what you are describing, you would either need to set
the form to post to the second page to begin with, or you would need to do a
Server.Transfer to the second page.

"melinda" <melinda@.discussions.microsoft.com> wrote in message
news:5033F7C5-5EB7-446E-B145-2B3443C58ECF@.microsoft.com...
> Ok, sorry if this is dumb ?, but I'm extremely new to ASP.net. I've used
> PHP and am now trying to figure out the best way (or any way) to do this
> in
> ASP.net:
> I have a page where the user enters data and clicks a submit button which
> redirects to another page. This 2nd page can retrieve all of the POST
> variables submitted from the previous page. How is this done in ASP.net?
> Thanks!
You can save the values to a a session and redirect the page to the
second page and then read from the session.

Also, this might help:

http://authors.aspalliance.com/kenc/passval.aspx

Shahid
"melinda" <melinda@.discussions.microsoft.com> wrote in message
news:5033F7C5-5EB7-446E-B145-2B3443C58ECF@.microsoft.com...
> Ok, sorry if this is dumb ?, but I'm extremely new to ASP.net. I've used
> PHP and am now trying to figure out the best way (or any way) to do this
> in
> ASP.net:
> I have a page where the user enters data and clicks a submit button which
> redirects to another page. This 2nd page can retrieve all of the POST
> variables submitted from the previous page. How is this done in ASP.net?
> Thanks!

ASP.NET forms by default submit to self.

I generally put my code in the button click server event. Then I redirect
to the next page if all goes well.

John
There are different technique to transfer data from one page to another. The
simple and easy way is to use Session Variable. You can also use QueryString.
For Session variable, You can save the values to a session and redirect the
destination page and then read the date from the session.

let there are two pages WebForm1.aspx and WebForm2.aspx. on the WebForm1 you
have 2 string variables and u want to access these two variables on 2nd page

U have to do on the Webform1.aspx:

string name = "Irfan";
string age = 30;

Session["anySessionVariableName1"] = name;
Session["anySessionVariableName2"] = age;

Response.Redirect("WebForm2.aspx");

on the WebForm2.aspx, u have to do for retrieving the name and age:

string nm = Session["anySessionVariableName1"].ToString();
string ag = Session["anySessionVariableName2"].ToString();

"melinda" wrote:

> Ok, sorry if this is dumb ?, but I'm extremely new to ASP.net. I've used
> PHP and am now trying to figure out the best way (or any way) to do this in
> ASP.net:
> I have a page where the user enters data and clicks a submit button which
> redirects to another page. This 2nd page can retrieve all of the POST
> variables submitted from the previous page. How is this done in ASP.net?
> Thanks!
There are different technique to transfer data from one page to another. The
simple and easy way is to use Session Variable. You can also use QueryString.
For Session variable, You can save the values to a session and redirect the
destination page and then read the date from the session.

let there are two pages WebForm1.aspx and WebForm2.aspx. on the WebForm1 you
have 2 string variables and u want to access these two variables on 2nd page

U have to do on the Webform1.aspx:

string name = "Irfan";
string age = 30;

Session["anySessionVariableName1"] = name;
Session["anySessionVariableName2"] = age;

Response.Redirect("WebForm2.aspx");

on the WebForm2.aspx, u have to do for retrieving the name and age:

string nm = Session["anySessionVariableName1"].ToString();
string ag = Session["anySessionVariableName2"].ToString();

"melinda" wrote:

> Ok, sorry if this is dumb ?, but I'm extremely new to ASP.net. I've used
> PHP and am now trying to figure out the best way (or any way) to do this in
> ASP.net:
> I have a page where the user enters data and clicks a submit button which
> redirects to another page. This 2nd page can retrieve all of the POST
> variables submitted from the previous page. How is this done in ASP.net?
> Thanks!

Friday, March 16, 2012

Password Field and Session Vars

Hey, I'm not sure what happened, but I ran into a simple problem I can't figure out.

All I'm trying to do is read two text boxes, txtUserEmail and txtUserPassword. I then take the txtUserEmail value and pass it into a stored proc, which matches it against an Email address in the MSDE. The stored proc returns the UserEmail, UserPassword, UserGroup (role) and UserEmailConfirm.

All I wanted to do is check txtUserEmail.text and txtUserPassword vs the UserEmail and UserPassword fields in my table that I'm getting back from the stored proc. Based on a match, I want to set a couple of Session vars.

fnReturnDataSet is in another module. It takes the stored proc call and returns the data set with the appropriate information.

The problem is that the Sub is skipping over the FOR loop and I'm not sure why. I know I'm only returning one row, but it's easy to just use this temeplate to get the dataset since it's working on 4 other pages I wrote.

If anyone could give me a hint what's wrong, I'd appriciate it.

--------------

Protected Sub btnUserLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUserLogin.Click
Dim strUserEmail, strUserPassword As String
Dim objSQL As String
Dim dsUserInfo As DataSet
Dim row As DataRow

strUserEmail = txtUserEmail.Text
strUserPassword = txtUserPassword.Text

objSQL = "EXECUTE spValidateUser '" & strUserEmail & "'"
dsUserInfo = fnReturnDataSet(objSQL)

For Each row In dsUserInfo.Tables("dtReturnedTable").Rows
If (row("UserEmail") = strUserEmail) And (row("UserPassword") = strUserPassword) And (row("UserEmailConfirm") = "yes") Then
Session("User") = row("UserEmail")
Session("UserGroup") = row("UserGroup")
lblConfirm.Text = "You are now logged in"
Else
lblError.Text = "The username or password provided are not valid"
End If
Next
End Subhello, have u tried to add
row("UserEmail").ToString() = strUserEmail ...

try it.
I actually figured everything out, but thank you for the suggestion.

I also found an article with some encryption classes to use:
http://www.15seconds.com/issue/021210.htm

I have the cookie encrypted as far as I can tell. I set one key to the UserName and a second to a UserRole. I just need to encrypt the passwords in my SQL database and I should be all set.

Eric