By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,156 Members | 962 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,156 IT Pros & Developers. It's quick & easy.

Passing Data with Hidden Fields asp.net

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.