I have dynamically created hidden input controls in a c# codebehind file, and then populate their values with javascript. I now want to access these variables in c#.
Firebug shows that the values do change with javascript, but i'm getting the origional values back in the code behind. Any insight would be much appreciated.
Javascript:
function injectVariables(){
var hidden = document.getElementById("point1");
hidden.value = 55;
var hidden2 = document.getElementById("point2");
hidden2.value = 55;
var hidden3 = document.getElementById("point3");
hidden3.value = 55;
alert("values changed");
}
ASPX
<asp:Button OnClick="Update_PlanRisks" OnClientClick="injectVariables()" Text="updatePlanRisks" runat="server" />
C#
protected override void CreateChildControls()
{
base.CreateChildControls();
int planId = Convert.ToInt32(Request.QueryString.Get("plan"));
planRisks = wsAccess.GetPlanRiskByPlanId(planId);
foreach (PlanRisk pr in planRisks)
{
HtmlInputHidden hiddenField = new HtmlInputHidden();
hiddenField.ID= "point" + pr.Id;
hiddenField.Name = "point" + pr.Id;
hiddenField.Value = Convert.ToString(pr.Severity);
this.Controls.Add(hiddenField);
}
}
protected void Update_PlanRisks(object sender, EventArgs e)
{
foreach (PlanRisk pr in planRisks)
{
int planRiskId = pr.Id;
string planRiskName = "point" + pr.Id;
HtmlInputHidden hiddenControl = (HtmlInputHidden) FindControl(planRiskName);
string val = hiddenControl.Value;
}
}