简体   繁体   English

Hiddenfield WebControl

[英]Hiddenfield WebControl

            foreach (var item in AnketSoru)
        {
            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." “ InvalidCastException未由用户代码处理。”

'System.Web.UI.WebControls.TextBox' türündeki nesne 'System.Web.UI.WebControls.HiddenField' türüne atılamadı. “ System.Web.UI.WebControls.TextBox”在“ System.Web.UI.WebControls.HiddenField”中。

I'm trying to reach hiddenfields value's and set them to the freeTxtQues value but couldn't able to do it for now. 我正在尝试达到hiddenfields值并将其设置为freeTxtQues值,但暂时无法执行此操作。 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. 创建动态控件时,需要在Init事件上创建它们,因此,在应用ViewState时,他会找到控件并设置其值。 If you are not creating the controls in Init but later, you will found out that the control doesn't have the supposed value! 如果不是在Init中创建控件,而是稍后再创建,则将发现该控件没有假定的值!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM