Do all the things like ++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatarSign Up
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple APILearn More
This is really bad practices. Don't mix langs.
@Cultist what do you mean "don't mix langs"? Isn't this exactly how you bring your C# variables over to frontend in Asp.net projects?
Mind you I'm learning as I go here, I'm just trying to find my way around this project.
Do you have any resource on the correct way to do it?
Can you elaborate? Do I need to set up an API and Ajax to get them or how do I go about that?
@ArcaneEye you should check how to do an API centric app.
I'm really not a fan of C# so can't say if it's idiomatic but as a general rule of thumb it's a bad idea to mix two or more languages together. Reminds me of old school php.
What you can do is transport the data to your client, basically you have your server in C#, your client in JS and a transport which is likely HTTP (REST).
The client does not need to know anything about how the data is generated.
The server does not need to know anything about how the data is consumed.
@Cultist "Don't mix langs" - ever talked to a DB in your backend? ;)
@Cultist right, so I'm asking how to do a specific thing in asp.net and you're basically saying "don't" :-p
Sadly I do not have the time on hand to restructure the whole thing to use rest api's, and considering data transfer is built into asp.net I don't have to, I'm just asking if anyone know of a way to share an aspx-codepage between multiple actual pages, but the more I look for it the less it appears to be possible. It's have been nice to cut back on the code duplication a bit, but I digress.
@PrivateGER this thing makes me want to kill a dev on a daily basis.
I'll keep what you said in mind, but I've little hope of getting to refactor it all anytime soon, and right now I wouldn't know what to use of not Ajax calls - there are much graver things in the codebase to the point where it's a relief when things are just plain broken 'cause at least then you can rebuild it :-p
Btw by AJAX they mean XHR using XMLHttpRequest I guess because ajax in itself does not exist... it's just a « technique ».
Then yeah, you prolly want to favor fetch over it if you don't need to track the progress of your request.
The other answers are correct, I'll just add this:
If it's an actual aspx (web form)... rearchitect, you're basically spraying money out of your servers onto the internet as bandwidth and cpu time prognosticating html payloads.
If you absolutely have to do this, the "correct" way is to wire up some form controls and use controlstate, which will serialize a ridiculous amount of data to the client and bind a form. It will then use that same serialized form representation to process the data into an object that you handle in the Page_Load event by checking if the form IsPostback in the "codebehind."
The reason you couldn't get any answers from google is you'd need to hop in the wayback machine, or target the Indian internet to find anyone still talking about it:
@SortOfTested this just makes me want to burn the whole project even more :-p
It's just that apparently the old <%=property.value%> is used as well and not knowing better I took it for standard, since my colleagues aren't cursing at that specific part quite so often.
Guess I'd best fire up pliralsight and have a closer look at what's what in the Microsoft webapp environment...
Well, like I said, the others are right.
Worst case, just drop an .ashx in the project and use that as your baseline data to transmit the values. Anything you render out to the page will inevitably be technical debt and have crosscutting concerns galore. Better to have it encapsulated at the call site in JS using fetch/xmlhttprequest.