When my page loads, it stores an id from the database into session: Session["AppId"] = 1234
. However, when I am doing JavaScript stuff, I need to know that AppId for database calls. How can I make that available to my JS from the server code? Would registering a script tag with var appId = 1234
be the way to go or does that code smell a bit too ripe?
Would adding a custom-attribute to the body tag make more sense? data-appid=1234
for example?
I'm new to web stuff, so the do's and don't's aren't always obvious to me. If there's a right/best way, feel free to share it.
The solution I actually needed was HttpContext.Current.Session["AppId"]
. I didn't think static methods could access session values, so I thought I had to store it in the mark-up to pass to my WebMethod through an Ajax call. I accepted the answer I did because it answered the question I asked. I just asked the wrong question. =) I'm new remember - go easy on me!
There are many ways to do this:
data-*
attributeThere is no consensus on which is best.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With