How to: Use similiar Php $_POST[''] array functionality in ASP.NET.

jorgebucaran

Newcomer
Joined
Jul 7, 2006
Messages
2
Hello all.

I have used in PHP a cool way to send data to webforms (either self-post or posting to other pages) using the $_POST[] global array. In ASP.Net I have used the querystring to accomplish similar functionality. However, now, I need to send data to pages (actually to the same page, self-post) but not through the querystring but using "behind-the-scenes" data passing, like I have in PHP.

Hope you can help. I want to implment similar functionality in ASP.Net.

P.S: I'm aware I could get away with session variables, so try other way please. ;)
 
Gill Bates said:
The values that are posted to the page can be found in the Request.Form collection.
Yes. That is fine to retrieve the data. The problem is sending the data. I want to send random, app-specific, variable data. My own data, not data set in textboxes or dropdown combos.

It would be great If I could do this:
Code:
Sub Page_Load()
   If Page.IsPostBack Then
       Response.Write(Request.Form("myVariable1"))    
   Else
       Request.Form.Add("myVariable1", data1)
       Request.Form.Add("myVariable2", data2)
       Request.Form.Add("myVariable3", data3)
   End If
End Sub
But the Request.Form collection is readonly. If you can help me with this, you might tell me also why is that this collection is readonly. What is wrong with my logic.

Thanks again.
 
just create html elements with the data you want...

<form id="form1" name="form1" method="post" action="this.aspx" style="display:none">
<input type="hidden" id="data1" name="data1" />
<input type="hidden" id="data2" name="data2" />
</form>

document.getElementById("form1").submit();

you can create dynamic elements also...

var data3 = document.createElement("input");
data3.type = "hidden";
data3.value = "something";


document.getElementById("form1").appendChild(data3);
 
Back
Top