简体   繁体   中英

Webmatrix - Passing variable from cshtml page to an aspx page

I'm using Webmatrix to build my site which renders different fusioncharts when users click on different buttons, ie if they click on the "Europe" button, they get a graph of avg temperatures in Europe, if they click on US, US avg temperatures etc...

The cshtml page holds the session variable UserId after succesful login and if that user clicks a button if(ispost) code refreshes the whole cshtml page which then contains an updated graph.

On refresh, within the cshtml page there is an iframe whose source is a file called "Using_MS_SQL_Server.aspx" which in turn creates an xml file populated by the execution of a stored procedure on the ms sql database like so:

SqlCommand query = new SqlCommand(
    "EXEC ON_WEBSITE_SQL_DB.dbo.AVG_TEMPS_PER_CONTINENT "
     + AREA + ", " + USERID, conn);   

As you can tell, there are two variables to plug into the stored proc: AREA and USERID...

Within the aspx.cs page's code I can easily call the USERID variable as it is a session variable using MembershipUser user = Membership.GetUser(); .

How do I pass a variable with the value "EUROPE" from the cshtml page that the user is clicking to the aspx page for use in the stored procedure that is waiting for the AREA variable?

The only ways you'd be able to achieve that is either using session/cookies or the query string.

If the data you're passing isn't sensitive information, then just go with the query string. If it is sensitive, think about encrypting either a session or cookie value that you can decrypt on the Page_Load of the ASPX.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM