Asp.net: (c# Client-side) How To Access Html Element Created After Page Loads?
Solution 1:
You cannot create a "real" runat=server element/control without doing a full postback to the server.
The best approach may be to write some script that stores the innerHTML into an ASP.Net hidden field right before you submit the page. You can then access the value of this hidden field to grab the data.
If you're wanting to dynamically create multiple objects, you'll need to use standard html hidden input fields instead, since you can't create asp.net server controls via javascript.
<inputtype="hidden" name="fieldData_1" value="control 1 html content">
<inputtype="hidden" name="fieldData_2" value="control 2 html content">
You'll then be able to access these hidden fields from the Request.Form object:
Request.Form["fieldData_1"]
Knowing this, you can now iterate over the form data and process all of your dynamic fields
foreach (string fieldData in Request.Form)
{
if(fieldData.Contains("fieldData_"){
//process the data for each field
}
}
It is also possible to avoid using hidden fields all together and just pass your data to the server directly using the __doPostback('', '') method. This could be implemented in many different ways, so I'll just refer you to http://dopostback.net to read up on how the method works.
Solution 2:
Add runat="server"
attribute to the tag to make it HTML Control and can be accessible from .cs file by its ID
Solution 3:
I think you need to post the element inner HTML back to the server. What I would do, in a client function, get the inner HTML of the newly created element, store it in a hidden field, then call __doPostBack('<hidden element id>', '');
Post a Comment for "Asp.net: (c# Client-side) How To Access Html Element Created After Page Loads?"