473,385 Members | 1,925 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,385 software developers and data experts.

Passing Data with Hidden Fields asp.net

Whats the best way to pass Data with hidden fields in asp.net.
I want to capture a LOGON_USER(from an intranet using Windows
Authentication)and then send the data to a table in the Database.
Any ideas?
Nov 19 '05 #1
5 1966
Hi Patrick,

Perhaps you could explain further what you need to accomplish?

Are you getting the name of LOGON_USER from the current page and doing the
data insert in that same page? If so, you don't need a hidden field. Just
put the userid into a local variable and pass it into your SQL insert.

Let us know a little more?

Ken

"Patrick.O.Ige" <Pa*********@discussions.microsoft.com> wrote in message
news:79**********************************@microsof t.com...
Whats the best way to pass Data with hidden fields in asp.net.
I want to capture a LOGON_USER(from an intranet using Windows
Authentication)and then send the data to a table in the Database.
Any ideas?


Nov 19 '05 #2
Ken thats exactly what i want to do..!
the LOGON_USER to the Database and the time entered..
If i don't need to use hidden files..
Can you show me another way i can do this in SQL as you stated!
Thanks!

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 19 '05 #3
Hi Patrick,

Here's how I'd do it. The code below uses SQL Server.

Make sure you're not allowing Anonymous access to the Web.

Let us know if this helps?

Ken
Microsoft MVP [ASP.NET]
Toronto
Private Sub Page_Load _
(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles MyBase.Load
' By Ken Cox - Microsoft MVP [ASP.NET]
' Get the Logged on user
' Make sure Anonymous is not checked in IIS Manager
' otherwise this may be empty
Dim strLogonUsr As String
strLogonUsr = Request.ServerVariables("LOGON_USER")
Dim myConnection = New SqlConnection("server=p4320;" _
& "Initial Catalog=logonusr;User ID=logonusruser;" & _
"Password=logonusruser;")
' Build a SQL INSERT statement string for all the input-form
' field values.
Dim insertCmd As String = _
"insert into LogDetail values (@Logon_User, @Logon_Time);"
' Initialize the SqlCommand with the new SQL string.
Dim myCommand = New SqlCommand(insertCmd, myConnection)
' Create new parameters for the SqlCommand object and
' initialize them to the field values.
' Create the parameter for the logon user
myCommand.Parameters.Add(New SqlParameter("@Logon_User", _
SqlDbType.VarChar, 50))
' Assign the value
myCommand.Parameters("@Logon_User").Value = strLogonUsr
' Create the parameter for the time
myCommand.Parameters.Add(New SqlParameter("@Logon_Time", _
SqlDbType.DateTime, 8))
' Assign the value as Now()
myCommand.Parameters("@Logon_Time").Value = Now()
myCommand.Connection.Open()

Try
' Execute the command
myCommand.ExecuteNonQuery()
' Report success
Label1.Text = "Inserted!"
Catch exc As SqlException
' Report trouble
Label1.Text = exc.Message
Finally
' Close the connection no matter what
myCommand.Connection.Close()
End Try
End Sub

<form id="Form1" method="post" runat="server">
<asp:Label id="Label1" runat="server">Label</asp:Label>
</form>
"Patrick Olurotimi Ige" <ig*@iprimus.com.au> wrote in message
news:ea**************@tk2msftngp13.phx.gbl...
Ken thats exactly what i want to do..!
the LOGON_USER to the Database and the time entered..
If i don't need to use hidden files..
Can you show me another way i can do this in SQL as you stated!
Thanks!

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


Nov 19 '05 #4
Thx Ken..
I used another approach which i used Hidden input textbox.
But your approach looks more interesting..!!!
Patrick


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 19 '05 #5
Ken for the sample but i have another Questions below:-
--------------------------------------------------------
When u click on the SURVEY link it checks if the USER is in the Database
if he/she is in the DB it retunrs access denied Which i have done.
And if they aren't INSERT the user..

But getting problems with my stored procedure below:-

CREATE procedure oyinbo(@username varchar(50), @password varchar(50) )
as
if exists
-- You cannot register usernames already registered on the database
twice.
(
select username from register where username = @username
)
return 1 else
insert register(username,password) values(@username,@password)
GO

It checks the USER and denies it but it never gives me access to the
page ...which i think it inserts the user before checking..
My codebehind is :-
Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here

conn = New
SqlConnection("server=(local);database=mydatabase; integrated
security=true;")
conn.Open()
txtuser.ID = Request.ServerVariables("LOGON_USER")

cmdcommand = New SqlCommand("rote", conn)
cmdcommand.CommandType = CommandType.StoredProcedure
param = cmdcommand.Parameters.Add("ReturnValue", SqlDbType.Int)
param.Direction = ParameterDirection.ReturnValue
cmdcommand.Parameters.Add("@username", txtuser.Name)

'cmdcommand.Parameters.Add(New SqlParameter("@DateCreated",
SqlDbType.DateTime, 8))
'cmdcommand.Parameters("@DateCreated").Value = Now()

cmdcommand.ExecuteNonQuery()

If cmdcommand.Parameters("ReturnValue").Value = 1 Then

Response.redirect("noaccess.aspx")
' lblMessage.Text = "Username already exists!"
Else

' lblMessage.Text = "Success!"
Response.Redirect("startsurvey.aspx")

End If


conn.Close()
End Sub
Anything i'm doing wrong?


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 19 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Paul | last post by:
Hmmm, didn't seem to work. I have set session.use_cookies = 1 and session.use_trans_sid = 1 in my php.ini file. Index.php contains:...
4
by: Ryann | last post by:
Hello. I am creating a form that has 5 steps/pages. Each page contains about 20 fields. But I don't want to write them until they submit on the last page. I figured out that I can use hidden...
0
by: Mario T. Lanza | last post by:
Seasoned ASP Developers, I have developed an ASP page that displays multiple rows of data with which the user may work. As each row is updated, the graphical info displayed immediately beside...
12
by: Patrick | last post by:
I have two ASP pages payment.asp: For customers to fill in payment/card details (pre-populating details if details submitted were invalid and user had to re-fill in details) confirmorder.asp:...
5
by: Matt Williamson | last post by:
I have a table that gets generated every 5 minutes containing the drive space on my servers. The table is sortable via an external javascript file by clicking the column headers (using sortable.js...
3
by: SV | last post by:
Dear all, In my application I have a lot of hidden fields. I want to make them invisible for the users though for debugging reasons I want to make them visible. So I want to add these objects to...
6
by: Jerry Camel | last post by:
Basic Web Form... A few text boxes and a checkbox - and a card reader... The effect I want to accomplish is this: The basic credit card fields are there and can be filled out. But if the user...
28
by: Skeets | last post by:
i'm passing session and hidden variables between pages. not to mention post values. i'm a little concerned that someone with sufficient knowledge could spoof these vlaues and manipulate the...
4
by: jej1216 | last post by:
I'm pretty new to PHP and MySQL. I have managed to create a form that inserts data to MySQL and to create a form to search the DB. Now here is my problem. I am unsuccessful coding a hidden...
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: 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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.