property. Almost everything is fine, except a really weird behavior with
the HtmlTextArea control. I noticed that if it has a value (some text
inside!) it's NOT recognized as an HtmlTextArea in the loop, while if
it's blank the condition hits. Btw using FindControl the text area is
correctly recognized and the value is there.
How is it possible? Does the "is" work?
Any suggestion?
Here is the code:
private void saveControlsToXml(Control parent, ref string xmlOut) {
string xmlTemplate =
"<Control><ID>{0}</ID><Text>{1}</Text><Value>{2}</Value></Control>";
foreach (Control c in parent.Controls) {
if (c.HasControls()) {
saveControlsToXml(c, ref xmlOut);
}
else {
if (c is System.Web.UI.HtmlControls.HtmlTextArea) {
HtmlTextArea t = (HtmlTextArea)(c);
xmlOut += string.Format(xmlTemplate, t.ID, t.InnerText, "");
continue;
}
if (c is System.Web.UI.WebControls.TextBox) {
TextBox t = (TextBox)(c);
xmlOut += string.Format(xmlTemplate, t.ID, t.Text, "");
continue;
}
if (c is System.Web.UI.WebControls.DropDownList) {
DropDownList d = (DropDownList)(c);
if (d.SelectedItem != null) {
xmlOut += string.Format(xmlTemplate, d.ID, d.SelectedItem.Text,
d.SelectedValue);
}
continue;
}
if (c is System.Web.UI.WebControls.RadioButton) {
RadioButton t = (RadioButton)(c);
xmlOut += string.Format(xmlTemplate, t.ID, "", t.Checked.ToString());
continue;
}
if (c is System.Web.UI.HtmlControls.HtmlInputText) {
HtmlInputText t = (HtmlInputText)(c);
xmlOut += string.Format(xmlTemplate, t.ID, t.Value, "");
continue;
}
if (c is System.Web.UI.HtmlControls.HtmlInputCheckBox) {
HtmlInputCheckBox t = (HtmlInputCheckBox)(c);
xmlOut += string.Format(xmlTemplate, t.ID, "", t.Checked.ToString());
continue;
}
if (c is System.Web.UI.HtmlControls.HtmlInputRadioButton) {
HtmlInputRadioButton t = (HtmlInputRadioButton)(c);
xmlOut += string.Format(xmlTemplate, t.ID, "", t.Checked.ToString());
continue;
}
}
}
}I did the following:
foreach ...
try {
HtmlControl t = (HtmlControl)(c);
xmlOut += string.Format(xmlTemplate, t.ID, "", "");
continue;
} catch {}
the HtmlTextArea is not even recognized as an HtmlControl, it's not there!
Mattia Saccotelli wrote:
> Hi to all. I'm trying to auto-save a form to XML using Page.Controls
> property. Almost everything is fine, except a really weird behavior with
> the HtmlTextArea control. I noticed that if it has a value (some text
> inside!) it's NOT recognized as an HtmlTextArea in the loop, while if
> it's blank the condition hits. Btw using FindControl the text area is
> correctly recognized and the value is there.
> How is it possible? Does the "is" work?
> Any suggestion?
> Here is the code:
> private void saveControlsToXml(Control parent, ref string xmlOut)
> {
> string xmlTemplate =
> "<Control><ID>{0}</ID><Text>{1}</Text><Value>{2}</Value></Control>";
> foreach (Control c in parent.Controls) {
> if (c.HasControls()) {
> saveControlsToXml(c, ref xmlOut);
> }
> else {
> if (c is System.Web.UI.HtmlControls.HtmlTextArea) {
> HtmlTextArea t = (HtmlTextArea)(c);
> xmlOut += string.Format(xmlTemplate, t.ID, t.InnerText, "");
> continue;
> }
> if (c is System.Web.UI.WebControls.TextBox) {
> TextBox t = (TextBox)(c);
> xmlOut += string.Format(xmlTemplate, t.ID, t.Text, "");
> continue;
> }
> if (c is System.Web.UI.WebControls.DropDownList)
> {
> DropDownList d = (DropDownList)(c);
> if (d.SelectedItem != null) {
> xmlOut += string.Format(xmlTemplate, d.ID, d.SelectedItem.Text,
> d.SelectedValue);
> }
> continue;
> }
> if (c is System.Web.UI.WebControls.RadioButton) {
> RadioButton t = (RadioButton)(c);
> xmlOut += string.Format(xmlTemplate, t.ID, "", t.Checked.ToString());
> continue;
> }
> if (c is System.Web.UI.HtmlControls.HtmlInputText) {
> HtmlInputText t = (HtmlInputText)(c);
> xmlOut += string.Format(xmlTemplate, t.ID, t.Value, "");
> continue;
> }
> if (c is System.Web.UI.HtmlControls.HtmlInputCheckBox) {
> HtmlInputCheckBox t = (HtmlInputCheckBox)(c);
> xmlOut += string.Format(xmlTemplate, t.ID, "", t.Checked.ToString());
> continue;
> }
> if (c is System.Web.UI.HtmlControls.HtmlInputRadioButton) {
> HtmlInputRadioButton t = (HtmlInputRadioButton)(c);
> xmlOut += string.Format(xmlTemplate, t.ID, "", t.Checked.ToString());
> continue;
> }
> }
> }
> }
Try using the Request.Form collection instead.
I think it will contain hidden fields and such too, but should contain all
the data sent at least.
Hope it help
/Dan
"Mattia Saccotelli" <"m.saccotelli [AT] gruppostratos [DOT] com"> wrote in
message news:%23JvhMZ5AFHA.1388@.TK2MSFTNGP09.phx.gbl...
>I did the following:
> foreach ...
> try {
> HtmlControl t = (HtmlControl)(c);
> xmlOut += string.Format(xmlTemplate, t.ID, "", "");
> continue;
> } catch {}
> the HtmlTextArea is not even recognized as an HtmlControl, it's not there!
>
> Mattia Saccotelli wrote:
>> Hi to all. I'm trying to auto-save a form to XML using Page.Controls
>> property. Almost everything is fine, except a really weird behavior with
>> the HtmlTextArea control. I noticed that if it has a value (some text
>> inside!) it's NOT recognized as an HtmlTextArea in the loop, while if
>> it's blank the condition hits. Btw using FindControl the text area is
>> correctly recognized and the value is there.
>> How is it possible? Does the "is" work?
>> Any suggestion?
>>
>> Here is the code:
>>
>> private void saveControlsToXml(Control parent, ref string xmlOut)
>> { string xmlTemplate =
>> "<Control><ID>{0}</ID><Text>{1}</Text><Value>{2}</Value></Control>";
>> foreach (Control c in parent.Controls) {
>> if (c.HasControls()) {
>> saveControlsToXml(c, ref xmlOut);
>> }
>> else { if (c is System.Web.UI.HtmlControls.HtmlTextArea) {
>> HtmlTextArea t = (HtmlTextArea)(c); xmlOut +=
>> string.Format(xmlTemplate, t.ID, t.InnerText, "");
>> continue;
>> }
>> if (c is System.Web.UI.WebControls.TextBox) {
>> TextBox t = (TextBox)(c);
>> xmlOut += string.Format(xmlTemplate, t.ID, t.Text, "");
>> continue;
>> }
>>
>> if (c is System.Web.UI.WebControls.DropDownList)
>> { DropDownList d =
>> (DropDownList)(c);
>> if (d.SelectedItem != null) {
>> xmlOut += string.Format(xmlTemplate, d.ID, d.SelectedItem.Text,
>> d.SelectedValue); }
>> continue;
>> }
>>
>> if (c is System.Web.UI.WebControls.RadioButton) {
>> RadioButton t = (RadioButton)(c);
>> xmlOut += string.Format(xmlTemplate, t.ID, "", t.Checked.ToString());
>> continue;
>> }
>>
>> if (c is System.Web.UI.HtmlControls.HtmlInputText) {
>> HtmlInputText t = (HtmlInputText)(c);
>> xmlOut += string.Format(xmlTemplate, t.ID, t.Value, "");
>> continue;
>> }
>>
>> if (c is System.Web.UI.HtmlControls.HtmlInputCheckBox) {
>> HtmlInputCheckBox t = (HtmlInputCheckBox)(c);
>> xmlOut += string.Format(xmlTemplate, t.ID, "", t.Checked.ToString());
>> continue;
>> }
>>
>> if (c is System.Web.UI.HtmlControls.HtmlInputRadioButton) {
>> HtmlInputRadioButton t = (HtmlInputRadioButton)(c);
>> xmlOut += string.Format(xmlTemplate, t.ID, "", t.Checked.ToString());
>> continue;
>> }
>> }
>> } }
Good idea, I'll do it whit the Form object.
I'd like to know the reason of such a strange behavior of the textarea.
Thanks!
Daniel Carlsson wrote:
> Try using the Request.Form collection instead.
> I think it will contain hidden fields and such too, but should contain all
> the data sent at least.
> Hope it help
> /Dan
> "Mattia Saccotelli" <"m.saccotelli [AT] gruppostratos [DOT] com"> wrote in
> message news:%23JvhMZ5AFHA.1388@.TK2MSFTNGP09.phx.gbl...
>>I did the following:
>>
>>foreach ...
>>try {
>>HtmlControl t = (HtmlControl)(c);
>>xmlOut += string.Format(xmlTemplate, t.ID, "", "");
>>continue;
>>} catch {}
>>
>>the HtmlTextArea is not even recognized as an HtmlControl, it's not there!
>>
>>
>>Mattia Saccotelli wrote:
>>
>>>Hi to all. I'm trying to auto-save a form to XML using Page.Controls
>>>property. Almost everything is fine, except a really weird behavior with
>>>the HtmlTextArea control. I noticed that if it has a value (some text
>>>inside!) it's NOT recognized as an HtmlTextArea in the loop, while if
>>>it's blank the condition hits. Btw using FindControl the text area is
>>>correctly recognized and the value is there.
>>>How is it possible? Does the "is" work?
>>>Any suggestion?
>>>
>>>Here is the code:
>>>
>>>private void saveControlsToXml(Control parent, ref string xmlOut)
>>>{ string xmlTemplate =
>>>"<Control><ID>{0}</ID><Text>{1}</Text><Value>{2}</Value></Control>";
>>>foreach (Control c in parent.Controls) {
>>>if (c.HasControls()) {
>>>saveControlsToXml(c, ref xmlOut);
>>>}
>>>else { if (c is System.Web.UI.HtmlControls.HtmlTextArea) {
>>> HtmlTextArea t = (HtmlTextArea)(c); xmlOut +=
>>>string.Format(xmlTemplate, t.ID, t.InnerText, "");
>>> continue;
>>>}
>>> if (c is System.Web.UI.WebControls.TextBox) {
>>> TextBox t = (TextBox)(c);
>>> xmlOut += string.Format(xmlTemplate, t.ID, t.Text, "");
>>> continue;
>>>}
>>>
>>>if (c is System.Web.UI.WebControls.DropDownList)
>>>{ DropDownList d =
>>>(DropDownList)(c);
>>> if (d.SelectedItem != null) {
>>> xmlOut += string.Format(xmlTemplate, d.ID, d.SelectedItem.Text,
>>>d.SelectedValue); }
>>> continue;
>>>}
>>>
>>>if (c is System.Web.UI.WebControls.RadioButton) {
>>> RadioButton t = (RadioButton)(c);
>>> xmlOut += string.Format(xmlTemplate, t.ID, "", t.Checked.ToString());
>>> continue;
>>>}
>>>
>>>if (c is System.Web.UI.HtmlControls.HtmlInputText) {
>>> HtmlInputText t = (HtmlInputText)(c);
>>> xmlOut += string.Format(xmlTemplate, t.ID, t.Value, "");
>>> continue;
>>>}
>>>
>>>if (c is System.Web.UI.HtmlControls.HtmlInputCheckBox) {
>>> HtmlInputCheckBox t = (HtmlInputCheckBox)(c);
>>> xmlOut += string.Format(xmlTemplate, t.ID, "", t.Checked.ToString());
>>> continue;
>>>}
>>>
>>>if (c is System.Web.UI.HtmlControls.HtmlInputRadioButton) {
>>> HtmlInputRadioButton t = (HtmlInputRadioButton)(c);
>>> xmlOut += string.Format(xmlTemplate, t.ID, "", t.Checked.ToString());
>>> continue;
>>>}
>>>}
>>>} }
>
I dont think ASP creates controls for the Html controls most of the time
(unlike the web form controls, like TextBox) so if its the "Text Area"
control Im surprised you got a control for it at any point. I havent used
those controls much yet though so not certain.
/Dan
"Mattia Saccotelli" <"m.saccotelli [AT] gruppostratos [DOT] com"> wrote in
message news:ufsm6j5AFHA.3824@.TK2MSFTNGP10.phx.gbl...
> Good idea, I'll do it whit the Form object.
> I'd like to know the reason of such a strange behavior of the textarea.
> Thanks!
>
> Daniel Carlsson wrote:
>> Try using the Request.Form collection instead.
>> I think it will contain hidden fields and such too, but should contain
>> all the data sent at least.
>>
>> Hope it help
>> /Dan
>>
>> "Mattia Saccotelli" <"m.saccotelli [AT] gruppostratos [DOT] com"> wrote
>> in message news:%23JvhMZ5AFHA.1388@.TK2MSFTNGP09.phx.gbl...
>>
>>>I did the following:
>>>
>>>foreach ...
>>>try {
>>>HtmlControl t = (HtmlControl)(c);
>>>xmlOut += string.Format(xmlTemplate, t.ID, "", "");
>>>continue;
>>>} catch {}
>>>
>>>the HtmlTextArea is not even recognized as an HtmlControl, it's not
>>>there!
>>>
>>>
>>>Mattia Saccotelli wrote:
>>>
>>>>Hi to all. I'm trying to auto-save a form to XML using Page.Controls
>>>>property. Almost everything is fine, except a really weird behavior with
>>>>the HtmlTextArea control. I noticed that if it has a value (some text
>>>>inside!) it's NOT recognized as an HtmlTextArea in the loop, while if
>>>>it's blank the condition hits. Btw using FindControl the text area is
>>>>correctly recognized and the value is there.
>>>>How is it possible? Does the "is" work?
>>>>Any suggestion?
>>>>
>>>>Here is the code:
>>>>
>>>>private void saveControlsToXml(Control parent, ref string xmlOut)
>>>>{ string xmlTemplate =
>>>>"<Control><ID>{0}</ID><Text>{1}</Text><Value>{2}</Value></Control>";
>>>>foreach (Control c in parent.Controls) {
>>>>if (c.HasControls()) {
>>>>saveControlsToXml(c, ref xmlOut);
>>>>}
>>>>else { if (c is System.Web.UI.HtmlControls.HtmlTextArea) {
>>>> HtmlTextArea t = (HtmlTextArea)(c); xmlOut +=
>>>> string.Format(xmlTemplate, t.ID, t.InnerText, "");
>>>> continue;
>>>>}
>>>> if (c is System.Web.UI.WebControls.TextBox) {
>>>> TextBox t = (TextBox)(c);
>>>> xmlOut += string.Format(xmlTemplate, t.ID, t.Text, "");
>>>> continue;
>>>>}
>>>>
>>>>if (c is System.Web.UI.WebControls.DropDownList)
>>>>{ DropDownList d =
>>>>(DropDownList)(c);
>>>> if (d.SelectedItem != null) {
>>>> xmlOut += string.Format(xmlTemplate, d.ID, d.SelectedItem.Text,
>>>> d.SelectedValue); }
>>>> continue;
>>>>}
>>>>
>>>>if (c is System.Web.UI.WebControls.RadioButton) {
>>>> RadioButton t = (RadioButton)(c);
>>>> xmlOut += string.Format(xmlTemplate, t.ID, "",
>>>> t.Checked.ToString());
>>>> continue;
>>>>}
>>>>
>>>>if (c is System.Web.UI.HtmlControls.HtmlInputText) {
>>>> HtmlInputText t = (HtmlInputText)(c);
>>>> xmlOut += string.Format(xmlTemplate, t.ID, t.Value, "");
>>>> continue;
>>>>}
>>>>
>>>>if (c is System.Web.UI.HtmlControls.HtmlInputCheckBox) {
>>>> HtmlInputCheckBox t = (HtmlInputCheckBox)(c);
>>>> xmlOut += string.Format(xmlTemplate, t.ID, "",
>>>> t.Checked.ToString());
>>>> continue;
>>>>}
>>>>
>>>>if (c is System.Web.UI.HtmlControls.HtmlInputRadioButton) {
>>>> HtmlInputRadioButton t = (HtmlInputRadioButton)(c);
>>>> xmlOut += string.Format(xmlTemplate, t.ID, "",
>>>> t.Checked.ToString());
>>>> continue;
>>>>}
>>>>}
>>>>} }
>>
>
Normally it doesn't except you run them as "server" controls
(runat="server")
The strange thing is that the control "disapper" when I insert some text
inside..
I changed them to multiline TextBox btw
Daniel Carlsson wrote:
> I dont think ASP creates controls for the Html controls most of the time
> (unlike the web form controls, like TextBox) so if its the "Text Area"
> control Im surprised you got a control for it at any point. I havent used
> those controls much yet though so not certain.
> /Dan
> "Mattia Saccotelli" <"m.saccotelli [AT] gruppostratos [DOT] com"> wrote in
> message news:ufsm6j5AFHA.3824@.TK2MSFTNGP10.phx.gbl...
>>Good idea, I'll do it whit the Form object.
>>
>>I'd like to know the reason of such a strange behavior of the textarea.
>>
>>Thanks!
>>
>>
>>Daniel Carlsson wrote:
>>
>>>Try using the Request.Form collection instead.
>>>I think it will contain hidden fields and such too, but should contain
>>>all the data sent at least.
>>>
>>>Hope it help
>>>/Dan
>>>
>>>"Mattia Saccotelli" <"m.saccotelli [AT] gruppostratos [DOT] com"> wrote
>>>in message news:%23JvhMZ5AFHA.1388@.TK2MSFTNGP09.phx.gbl...
>>>
>>>
>>>>I did the following:
>>>>
>>>>foreach ...
>>>>try {
>>>>HtmlControl t = (HtmlControl)(c);
>>>>xmlOut += string.Format(xmlTemplate, t.ID, "", "");
>>>>continue;
>>>>} catch {}
>>>>
>>>>the HtmlTextArea is not even recognized as an HtmlControl, it's not
>>>>there!
>>>>
>>>>
>>>>Mattia Saccotelli wrote:
>>>>
>>>>
>>>>>Hi to all. I'm trying to auto-save a form to XML using Page.Controls
>>>>>property. Almost everything is fine, except a really weird behavior with
>>>>>the HtmlTextArea control. I noticed that if it has a value (some text
>>>>>inside!) it's NOT recognized as an HtmlTextArea in the loop, while if
>>>>>it's blank the condition hits. Btw using FindControl the text area is
>>>>>correctly recognized and the value is there.
>>>>>How is it possible? Does the "is" work?
>>>>>Any suggestion?
>>>>>
>>>>>Here is the code:
>>>>>
>>>>>private void saveControlsToXml(Control parent, ref string xmlOut)
>>>>>{ string xmlTemplate =
>>>>>"<Control><ID>{0}</ID><Text>{1}</Text><Value>{2}</Value></Control>";
>>>>>foreach (Control c in parent.Controls) {
>>>>>if (c.HasControls()) {
>>>>>saveControlsToXml(c, ref xmlOut);
>>>>>}
>>>>>else { if (c is System.Web.UI.HtmlControls.HtmlTextArea) {
>>>>> HtmlTextArea t = (HtmlTextArea)(c); xmlOut +=
>>>>>string.Format(xmlTemplate, t.ID, t.InnerText, "");
>>>>> continue;
>>>>>}
>>>>> if (c is System.Web.UI.WebControls.TextBox) {
>>>>> TextBox t = (TextBox)(c);
>>>>> xmlOut += string.Format(xmlTemplate, t.ID, t.Text, "");
>>>>> continue;
>>>>>}
>>>>>
>>>>>if (c is System.Web.UI.WebControls.DropDownList)
>>>>>{ DropDownList d =
>>>>>(DropDownList)(c);
>>>>> if (d.SelectedItem != null) {
>>>>> xmlOut += string.Format(xmlTemplate, d.ID, d.SelectedItem.Text,
>>>>>d.SelectedValue); }
>>>>> continue;
>>>>>}
>>>>>
>>>>>if (c is System.Web.UI.WebControls.RadioButton) {
>>>>> RadioButton t = (RadioButton)(c);
>>>>> xmlOut += string.Format(xmlTemplate, t.ID, "",
>>>>>t.Checked.ToString());
>>>>> continue;
>>>>>}
>>>>>
>>>>>if (c is System.Web.UI.HtmlControls.HtmlInputText) {
>>>>> HtmlInputText t = (HtmlInputText)(c);
>>>>> xmlOut += string.Format(xmlTemplate, t.ID, t.Value, "");
>>>>> continue;
>>>>>}
>>>>>
>>>>>if (c is System.Web.UI.HtmlControls.HtmlInputCheckBox) {
>>>>> HtmlInputCheckBox t = (HtmlInputCheckBox)(c);
>>>>> xmlOut += string.Format(xmlTemplate, t.ID, "",
>>>>>t.Checked.ToString());
>>>>> continue;
>>>>>}
>>>>>
>>>>>if (c is System.Web.UI.HtmlControls.HtmlInputRadioButton) {
>>>>> HtmlInputRadioButton t = (HtmlInputRadioButton)(c);
>>>>> xmlOut += string.Format(xmlTemplate, t.ID, "",
>>>>>t.Checked.ToString());
>>>>> continue;
>>>>>}
>>>>>}
>>>>>} }
>>>
>>>
0 comments:
Post a Comment