Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem passing User Name to SQL Paremeter

Status
Not open for further replies.

putrtek

Programmer
May 18, 2003
49
US
I'm using a Multi view nested inside <EditItemTemplate> of the Formview in order to simulate a Multi Page Wizard. I'm trying to pass the Username of the logged in user to a hidden field which in turn feeds a SQL parameter in order to update my database with the name user who edited the record.

I set the Value of the field in the Page Load fuction of the code behind to

UpdatedBy.Value = Context.User.Identity.Name

The hidden field shows up in Control Tree section of the Trace, It also shows up in the Forms Collection section of the Trace with the correct value assigned to it. However when I update the record the SQL Paremeter is blank.

Even if I set the Value of the Hidden Field in the Code behind to a static value the SQL paramter still blank when I try to update the record.

Can anyone give me an idea of what I might be doing wrong?

or Point me in the right direction?

Mark Buckley
 
what happens if you make the username appear in a visible control on the page?

failing that, how have you defined the SqlParameter?

K
 
Yes, Context.User.Identity.Name actually gives me a value it returns the correct value according to the Trace.

Yes I have defined the SqlParameter.

-MARK-

Mark Buckley
 
You're using a mulitview as a wizard. the only available controls in a given instance are the active view. this differs from the wizard control where all controls are available despite which step in active.

in other words only the active view controls are accessible with a multiview. All controls are accessible with a wizard.

If the hidden field is on an inactive multiview page the control is not available.

Question: if your passing the Username, why do you need to assign the value to a hidden control? Just pass User.Identity.Name to the SqlParameter.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Jason,

Thanks for replying...

OK... That makes sense however I have probally 5 Views within this multiview and the data from ALL of them Except this one hidden field passes to the Update function with no problem. So I'm a litlle confused as to why the hidden field wont pass like all the rest of them?


What would be the syntax for pasing User.Identity.Name to the SqlParameter ?
The only snytax I'm familar with would be

Code:
<UpdateParameters>
<asp:Parameter Name="UpdateBy" Type="String" />
</UpdateParameters>
The only way I could get this to work in the past would be to create a hidden field called UpdateBy and assign that field the value of the logged in User.

Mark Buckley
 
use the codebehind
Code:
SqlCommand.Parameters["UpdateBy"].Value = User.Identity.Name;
or the aspx
Code:
<asp:Parameter Name="UpdateBy" Type="String" Value='<%#User.Indentity.Name %>' />

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Hey Jason,

Thanks Agind for the asistance.

When I attempt to use this syntax I get an error saying 'Value' is not a valid attribute of Parameter. However DefaultValue IS so I changed your code to

Code:
<asp:Parameter Name="UpdateBy" Type="String" DefaultValue ='<%#User.Indentity.Name %>' ConvertEmptyStringToNull="true"  />

When I try to run this in the browser I get the following error.

Code:
Parser Error 
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately. 

Parser Error Message: Databinding expressions are only supported on objects that have a DataBinding event. System.Web.UI.WebControls.Parameter does not have a DataBinding event.

Source Error: 


Line 1884: <asp:Parameter Name="RtOP_Correction" Type="Int32" ConvertEmptyStringToNull="true"  />   
Line 1885: <asp:Parameter Name="RtOP_Resolution" Type="String" ConvertEmptyStringToNull="true"  />     
Line 1886: <asp:Parameter Name="UpdateBy" Type="String" DefaultValue ='<%#User.Indentity.Name %>' ConvertEmptyStringToNull="true"  />
Line 1887:                            
Line 1888:



Mark Buckley
 
you may need to use an equals sign instead of #
Code:
<asp:Parameter Name="UpdateBy" Type="String" DefaultValue ='<%[COLOR=red]=[/color]User.Indentity.Name %>' ConvertEmptyStringToNull="true"  />
If that doesn't work use the code behind.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
We are so close...

If I use the Syntax you suggested with the Equal sign it will update the record but it passes the literal value
<%=User.Indentity.Name %> instead of the Actual logged in Users Name.

I am able to create a text box and assigned the Text of the box to User.Indentity.Name and it displays the User Name in the text box correctly. I set the SQL Parameter to the text box but when I updated the record the Parameter is blank. If I set the Textbox to Bind to the Updatedby value from the database it will dsiplay the current value from the database and I am able to edit the text box and it WILL update with the value the I changed it to. Howeveer this doesn;t help me. I need to be able to update this field to the value of User.Indentity.Name beghind the scenes

I really appreciate the assistance you have ben giving me.

Mark Buckley
 
Jason,

I FINALLY got this to work using the following line in the Page Load Sub of the code behind file...

Code:
SqlDataSource1.UpdateParameters("UpdatedBy").DefaultValue = Context.User.Identity.Name

Thanks you so much for pointing me in the right direction.

Mark Buckley
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top