Here I come wh another newbie question about EpiServer, I hope you will be able to help me solve it...
I have created a form in my site with certain controls, like text boxes. I want to have a simple postback process, but when I send the form variables I realize that the post variables change, so that instead of having a request variable called MyVariable I have something like this:
Why this is happening, and can i configure something in order to get just the postback variable as "MyVariable"?
Thanks a lot for your help!
That behavior is not so much EPiServers as it is ASP.NET's. In ASP.NET all server controls are assigned a unique ID based on it's parents (or actually naming containers) unique IDs along with either a ID that you specify or a generated ID.
I'm guessing that "MyVariable" in your case is a textbox or some other forms element and you want to retrieve it's value. The postback concept in ASP.NET pretty much dictates that you should not retrieve the value of the POST-variable ctl00$MainRegion$MainContentRegion$MainBodyRegion$MyVariable but instead programatically access the server control MyVariable's Text property (if it's a TextBox). That is, you retrieve the value something like this:
string postedValue = MyVariable.Text;
Or if it is a checkbox:
bool postedValue = MyVariable.Checked;
The point here is that ASP.NET works slightly different from what we are used to when building web applications in other languages as it encapsulates state of elements for us and makes development more simillar to building client applications than stateless websites. The reason that it uses the full "path" of ID's is that you can have multiple controls with the same assigned ID (MyVariable) on the same page if your control is placed in a user control, repeater etc and ASP.NET needs to be able to distinguish between them.
I hope I've atleast partially answered your question above, if not I'm blaming it on the fact that it's sunday ;)
There is probably alot of good answers/tutorials/discussions about this in the ASP.NET community. A quick search found me this tutorial which seems pretty good at first glance.
Thanks a lot Joel about your nice answer, it gave me quite much light even if it's sunday :)
You are totally right, my knowledge about ASP.Net is not so wide, I come from VB.Net and PHP when it comes to web applications.
Actually my problem, is that I am not doing a real postback, because I overload the behaviour of the send button in my form in order to navigate to an external site (build in PHP, not EpiServer related, my point is to integrate my company services within an EpiServer site).
I guess that in this case, my only solution will be to parse the variable's names in order to get rid of the part of the path that I do not need.
Anyhow, thanks a lot for your answer!