Two questions related to ASP.NET loopback

Question 1) I have a control to which I add an attribute from the server side using a suggestion like:

ControlName.Attributes.Add("myTestAttribute", "")

      

From the client side, I change the value of this attribute using a Javascript function:

Document.getElementById(ControlName).setAttribute("myTestAttribute", "Hello Server!!");

      

My problem is when I try to access the value of an attribute in the Postback handling function, the attribute is empty. Am I missing a step?

Question 2) Is it possible to get the full HTML of the page on the server side from the Postback function?

0


a source to share


3 answers


If javascript modifies elements on the page, they will not be visible to the server. When a postback occurs, the only data available to the server is the data that is submitted in the form on the page.

ASP.net handles standard form elements like text boxes, dropdowns, etc. by putting their values ​​in a hidden field called viewstate (this is usually encoded so it can't be read directly).



If you want the javascript modified page elements to be visible to the server, you can write new hidden form elements and retrieve them from the Request [string name] array.

+1


a source


  • Place this attribute, add code to Page_Init
  • Nope


0


a source


In answer to question 2, you can store the status of these attributes in the view if you want to know their values ​​after postback.

0


a source







All Articles