I have document.form1.submit() in javascript. I want to know how it’s received in code behind. In which class, in which method? Something like that. Coz I want to get the value inside a textbox to store it in session. And do i need an actual “submit” button for this to work? This really confuses me.
If i put it like this:
function CallSubmit() {
var thetext = document.getElementById('textbox1').value;
document.form1.submit(thetext);
}
will I be able to pass the value of textbox1 to a specific method in code behind if it has, like, a receiving variable? I mean, how do i get the value of textbox1?
By the way, I’m trying to do this before the page unloads. Because I need to store the text from textbox1 so that I can re-assign that value back after the page refreshes.
You can get the post back values on code behind using the ‘Form’ as
and if you read this
Request.Formyou get all data from postComments.
In asp.net we general avoid to use direct the
Request.Formand we use asp.net controls that all ready handle the post values.For example if you use an
asp:TextBoxwithID=textBox1then you read the post fromtextBox1.Textand if you like to read it using the
Request.Formyou need to call theRequest.Form[textBox1.UniqueID]The
textBox1.UniqueIDis thenamevalue on the html control, and the name used for the post back.