Jump to content
Xtreme .Net Talk

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


Recommended Posts

Posted

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. ;)

Posted
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:

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.

Posted

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);

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...