Answered by:
get input:hidden value from code behind

Question
-
User-1471881183 posted
hello all,
im using a thrid party tool in A.aspx, while calling their functions im passing B.aspx as the response receiveing page.
now, everything are ok and response received in B.aspx, there is a input:hidden control with some data, i have to read its value from code behind so, i have written the code like below but, receiving only null as output.
protected void Page_Load(object sender, EventArgs e) { var responseJson = Request.Form["3FC23F6B"]; }
below is the output generated in B.aspx
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head><title> </title></head> <body> <form method="post" action="./b" id="form1"> <div class="aspNetHidden"> <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" /> </div> <div class="aspNetHidden"> <input type="hidden" name="__VIEWSTATEGENERATOR" id="__VIEWSTATEGENERATOR" value="3FC23F6B" /> </div> <div> </div> </form> </body> </html>May i know how to get this data in code behind?
Wednesday, August 5, 2020 11:55 AM
Answers
-
User-821857111 posted
You need to reference the form control by its
name
attribute value:var x = Request.Form["__VIEWSTATEGENERATOR"];
// x is 3FC23F6B
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, August 5, 2020 4:41 PM -
User-939850651 posted
Hi winseealn,
As other members said, I got the correct data.
A.html <body> <form method="post" action="B.aspx" id="form1"> <input name="input1" type="hidden" value="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" /> <input name="input2" type="hidden" value="3FC23F6B" /> <input type="submit" value="Submit" name="submit" /> </form> </body>
B.aspx.cs protected void Page_Load(object sender, EventArgs e) { var x = Request.Form["input1"].ToString(); var y = Request.Form["input2"].ToString(); Response.Write(x + "---" + y); }
Result:
Best regards,
Xudong Peng
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, August 6, 2020 4:09 AM
All replies
-
User-821857111 posted
You need to reference the form control by its
name
attribute value:var x = Request.Form["__VIEWSTATEGENERATOR"];
// x is 3FC23F6B
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, August 5, 2020 4:41 PM -
User-1471881183 posted
Mikes thanks for your response.
Yes I tried with viewstategenerator also but results null.Wednesday, August 5, 2020 7:02 PM -
User-939850651 posted
Hi winseealn,
As other members said, I got the correct data.
A.html <body> <form method="post" action="B.aspx" id="form1"> <input name="input1" type="hidden" value="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" /> <input name="input2" type="hidden" value="3FC23F6B" /> <input type="submit" value="Submit" name="submit" /> </form> </body>
B.aspx.cs protected void Page_Load(object sender, EventArgs e) { var x = Request.Form["input1"].ToString(); var y = Request.Form["input2"].ToString(); Response.Write(x + "---" + y); }
Result:
Best regards,
Xudong Peng
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, August 6, 2020 4:09 AM