Hiddenfield WebControl
foreach (var item in AnketSoru)
{
开发者_如何学Python r = new HtmlTableRow();
c = new HtmlTableCell();
c.InnerHtml = item.new_question_text.ToString();
r.Cells.Add(c);
switch (item.new_question_type.ToString())
{
case "2": //FreeText
c = new HtmlTableCell();
TxtFreeText = new TextBox();
TxtFreeText.ID = "Txt_" + item.new_survey_questionid.ToString();
TxtFreeText.TextMode = TextBoxMode.MultiLine;
TxtFreeText.Width = 300;
TxtFreeText.Height = 50;
TxtFreeText.EnableViewState = true;
c.Controls.Add(TxtFreeText);
HiddenField txthfield = new HiddenField();
txthfield.Value = item.new_name.ToString();
c.Controls.Add(txthfield);
and
foreach (Control c in plc.Controls)
{
System.Web.UI.HtmlControls.HtmlTable Survey_Inner = (System.Web.UI.HtmlControls.HtmlTable)c.FindControl("Survey_Inner");
foreach (System.Web.UI.HtmlControls.HtmlTableRow r in Survey_Inner.Rows)
{
foreach (Control ctr in r.Cells)
{
foreach (Control ct in ctr.Controls)
{
if (ct.GetType().ToString() == "System.Web.UI.WebControls.TextBox")
{
string freeTxtQues = ?? ;
string TextCevap = ((System.Web.UI.WebControls.TextBox)ct).Text;
string deger = ct.ID.ToString();
Guid QuestionId = new Guid(deger.Substring(4));
SaveAnswers(this._PortalUserHelper.UserProxy.ContactId, EgitimKatilimcisi, QuestionId, TextCevap, freeTxtQues);
}
i tryed
string freeTxtQues = ((System.Web.UI.WebControls.HiddenField)ct).Value;
but returns me error. "InvalidCastException was unhandled by user code."
'System.Web.UI.WebControls.TextBox' türündeki nesne 'System.Web.UI.WebControls.HiddenField' türüne atılamadı.
I'm trying to reach hiddenfields value's and set them to the freeTxtQues value but couldn't able to do it for now. Any help for how can i do that?
Hard to understand your question/problem but I will throw something...
When you create dynamic controls you need to create them on Init event so when ViewState is applied he finds the controls and sets their values. If you are not creating the controls in Init but later, you will found out that the control doesn't have the supposed value!
精彩评论