Hi Guys,
Im trying to pass a value from a C# page to the corresponding ASP page.
I want to use this value in my SQL Query on the asp page within a Details View.
Ive made the variable public in c# page.
And im trying to concatenate it to my sql query within the <asp: SqlDataSource.
Thanks.
Look at http://www.devx.com/webdev/Article/30811 (Passing Information Securely Between ASP and ASP.NET)From ASP to ASP.NET you could call MyAspNetPage.aspx?ID=1234 where 1234 is the id of the record to display.|||Im using these 2 lines of code in the C# Page to retrieve the UserId. UserNum ive made public.
Guid User = (Guid)Membership.GetUser().ProviderUserKey;
UserNum = User.ToString();
This is the select statement i want to use within the SQLDataSource.
SELECT * FROM [UserData] WHERE ([UserID] = @.UserNum)
@.UserNum i want to use as the parameter in the query.
I still cant get the value back into the @.UserNum of the query
|||Are you trying to pass information from an ASP.NET page to an ASP page?|||No.
I retrieve the UserID in the Account.aspx.cs page (This is the C# Page)
I want to pass the retrieved value to the Account.aspx page because i need to use it in a query in a SQL Data Source.
I thought i could just call the variable like this @.UserNum withint the query.
But its not picking up the value from the C# page.
|||Your question is now clear!
You need to populate the data control from within Account.aspx.cs. The SQL Data Source may get get some very quick results, but in the end end nothing beats regular coding.
data control?
Im not sure what you mean?
|||I was using "Data Control" generically - I shoudl have said to populate the Details View - it shoudl be done entirely from code behind.|||
Oh ok.
I am using a query behind the details view to populate it.
But i need to retrieve the current logged in User-ID so that i can populate it correctly.
Thats is why i was using the c# page.
Is it possible to retrieve the current logged in User-ID within SQL?
|||Assuming your back-end database is SQL Server, you can set up a stored procedure that takes the argument of the record id. To run it set up a command block and execute it.
Or you can just generate the SQL command dynamically as in http://www.dotnetjunkies.com/QuickStartv20/howto/doc/adoplus/GetDataFromDB.aspx
|||
We are using an MS SQL Server Database.
Is it possible to pass a value back from the C# page as a
<asp:Parameter> ?
|||Hi guys,I still havent figured this out.
This is the code im using in the asp page.
<asp:SqlDataSourceID="SqlDataSource1"runat="server"ConnectionString="<%$ ConnectionStrings:ASPNETDB.MDFConnectionString %>"
SelectCommand="SELECT FirstName, SecondName, DeviceNum, MobileNum, Address, Town, City, Country FROM aspnet_AddInformation WHERE (UserId = @.UserNumVal)"UpdateCommand="UPDATE aspnet_AddInformation SET FirstName =, SecondName =, DeviceNum =, MobileNum =, Address =, Town =, City =, Country ="><SelectParameters><asp:ParameterName="UserNum"DefaultValue="<%= UserNumVal %>"/></SelectParameters></asp:SqlDataSource>
This is the code i use in the C# Page to retrieve the userId Number
publicString UserNum;protectedvoid Page_Load(object sender, System.EventArgs e){
Guid User = (Guid)Membership.GetUser().ProviderUserKey;UserNum = User.ToString();
}
I want to use the value of UserNum within the query the SQL SelectCommand
I think i ahve to pass the value back as a parameter?
|||
We fixed the problem.
We needed to add the following line of code to the C# Page.
SqlDataSource1.SelectParameters.Add("userNum", userNum);
Thanks For all the help!
No comments:
Post a Comment