Гость
Целевая тема:
Создать новую тему:
Автор:
Форумы / ASP.NET [игнор отключен] [закрыт для гостей] / Dynamic <input type="radio"> / 13 сообщений из 13, страница 1 из 1
17.11.2005, 00:40
    #33382804
Ex_Soft
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Dynamic <input type="radio">
Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
<script type="text/javascript">
<!--
function AddRadio()
{
	var
		oTable,
		oTableBody,
		oRow,
		oCell;
	
	if(!(oTable=document.getElementById("TableRadio")))
		return;

	for(var i= 0 ; i<oTable.childNodes.length; ++i)
		if(oTable.childNodes[i].nodeType== 1  && oTable.childNodes[i].nodeName.toLowerCase()=="tbody")
		{
			oTableBody=oTable.childNodes[i];
			break;
		}
		
	if(!oTableBody)
		return;
		
	if(!(oRow=document.createElement("TR")))
		return;
	oTableBody.appendChild(oRow);

	if(!(oCell=document.createElement("TD")))
		return;
	oCell.innerHTML="<input type=\"radio\" id=\"<%=SignatureRadio%> 1 \" name=\"<%=SignatureRadio%>\" value=\"<%=SignatureRadio%>\" checked>";
	oRow.appendChild(oCell);

	if(!(oCell=document.createElement("TD")))
		return;
	oCell.innerHTML="<input type=\"radio\" id=\"<%=SignatureRadio%> 2 \" name=\"<%=SignatureRadio%>\" value=\"<%=SignatureRadio%> 2 \">";
	oRow.appendChild(oCell);
}
// -->
</script>
...
			<table id="TableRadio" border="1" runat="server">
				<tr>
					<td colspan="2"><input type="button" id="btnAddRadio" name="btnAddRadio" value="AddRadio" onclick="AddRadio()"></td>
				</tr>
			</table>
Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
protected string
	SignatureRadio="DynamicRadio";
...
		private void Page_Init(object sender, System.EventArgs e)
		{
			if(IsPostBack)
			{
				if(Request.Params.GetValues(SignatureRadio)!=null)
				{
					HtmlTableRow
						oRow;

					HtmlTableCell
						oCell;

					HtmlInputRadioButton
						tmpHtmlInputRadioButton;

					oRow=new HtmlTableRow();
					TableRadio.Rows.Add(oRow);

					oCell=new HtmlTableCell();
					tmpHtmlInputRadioButton=new HtmlInputRadioButton();
					tmpHtmlInputRadioButton.ID=SignatureRadio+"1";
					tmpHtmlInputRadioButton.Name=SignatureRadio;
					tmpHtmlInputRadioButton.Value=SignatureRadio+"1";
					oCell.Controls.Add(tmpHtmlInputRadioButton);
					oRow.Cells.Add(oCell);

					oCell=new HtmlTableCell();
					tmpHtmlInputRadioButton=new HtmlInputRadioButton();
					tmpHtmlInputRadioButton.ID=SignatureRadio+"2";
					tmpHtmlInputRadioButton.Name=SignatureRadio;
					tmpHtmlInputRadioButton.Value=SignatureRadio+"2";
					oCell.Controls.Add(tmpHtmlInputRadioButton);
					oRow.Cells.Add(oCell);
				}
			}
		}
не хочет выставлять checked у выбранного переключателя :( Хотя в Request'е есть, 4 example:

Key [4]=DynamicRadio
Value [0]=DynamicRadio2

Что надо еще покрутить-прикрутить? BTW, созданные аналогично <input type="text"...>, <input type="checkbox"...> заполняются на ура...
_________________
"Helo, word!" - 17 errors 56 warnings
...
Рейтинг: 0 / 0
17.11.2005, 01:12
    #33382818
Ex_Soft
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Dynamic <input type="radio">
Вдогонку: не хочет выставлять только при первом submit'е страницы - при последующих уже все нормально. BTW, созданные аналогично <input type="text"...>, <input type="checkbox"...> заполняются на ура на любом по счету submit'е...

/me как жаль, что нельзя редактировать...
_________________
"Helo, word!" - 17 errors 56 warnings
...
Рейтинг: 0 / 0
17.11.2005, 12:10
    #33383677
Ex_Soft
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Dynamic <input type="radio">
Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
<script type="text/javascript">
<!--
function Add()
{
	var
		oTable,
		oTableBody,
		oRow,
		oCell;
	
	if(!(oTable=document.getElementById("TableRadio")))
		return;

	for(var i= 0 ; i<oTable.childNodes.length; ++i)
		if(oTable.childNodes[i].nodeType== 1  && oTable.childNodes[i].nodeName.toLowerCase()=="tbody")
		{
			oTableBody=oTable.childNodes[i];
			break;
		}
		
	if(!oTableBody)
		return;
		
	if(!(oRow=document.createElement("TR")))
		return;
	oTableBody.appendChild(oRow);

	if(!(oCell=document.createElement("TD")))
		return;
	oCell.innerHTML="<input type=\"radio\" id=\"<%=SignatureRadio%> 1 \" name=\"<%=SignatureRadio%>\" value=\"<%=SignatureRadio%> 1 \" checked>";
	oRow.appendChild(oCell);

	if(!(oCell=document.createElement("TD")))
		return;
	oCell.innerHTML="<input type=\"radio\" id=\"<%=SignatureRadio%> 2 \" name=\"<%=SignatureRadio%>\" value=\"<%=SignatureRadio%> 2 \">";
	oRow.appendChild(oCell);
	
	if(!(oCell=document.createElement("TD")))
		return;
	oCell.innerHTML="<input type=\"text\" id=\"<%=SignatureText%>\" name=\"<%=SignatureText%>\">";
	oRow.appendChild(oCell);

	if(!(oCell=document.createElement("TD")))
		return;
	oCell.innerHTML="<input type=\"checkbox\" id=\"<%=SignatureCheckBox%>\" name=\"<%=SignatureCheckBox%>\">";
	oRow.appendChild(oCell);
}
// -->
</script>
...
			<table id="TableRadio" border="1" runat="server">
				<tr>
					<td colspan="4"><input type="button" id="btnAdd" name="btnAdd" value="Add" onclick="Add()"></td>
				</tr>
			</table>
Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
90.
91.
92.
93.
94.
95.
96.
97.
98.
99.
100.
101.
102.
protected string
	SignatureRadio="DynamicRadio",
	SignatureText="DynamicText",
	SignatureCheckBox="DynamicCheckBox";
...
		private void Page_Init(object sender, System.EventArgs e)
		{
			if(IsPostBack)
			{
				if(Request.Params.GetValues(SignatureRadio)!=null)
				{
					HtmlTableRow
						oRow;

					HtmlTableCell
						oCell;

					HtmlInputRadioButton
						tmpHtmlInputRadioButton;

					HtmlInputText
						tmpHtmlInputText;

					HtmlInputCheckBox
						tmpHtmlInputCheckBox;

					oRow=new HtmlTableRow();
					TableRadio.Rows.Add(oRow);

					oCell=new HtmlTableCell();
					tmpHtmlInputRadioButton=new HtmlInputRadioButton();
					tmpHtmlInputRadioButton.ID=SignatureRadio+"1";
					tmpHtmlInputRadioButton.Name=SignatureRadio;
					tmpHtmlInputRadioButton.Value=SignatureRadio+"1";
					oCell.Controls.Add(tmpHtmlInputRadioButton);
					oRow.Cells.Add(oCell);

					oCell=new HtmlTableCell();
					tmpHtmlInputRadioButton=new HtmlInputRadioButton();
					tmpHtmlInputRadioButton.ID=SignatureRadio+"2";
					tmpHtmlInputRadioButton.Name=SignatureRadio;
					tmpHtmlInputRadioButton.Value=SignatureRadio+"2";
					oCell.Controls.Add(tmpHtmlInputRadioButton);
					oRow.Cells.Add(oCell);

					oCell=new HtmlTableCell();
					tmpHtmlInputText=new HtmlInputText();
					tmpHtmlInputText.ID=SignatureText;
					oCell.Controls.Add(tmpHtmlInputText);
					oRow.Cells.Add(oCell);

					oCell=new HtmlTableCell();
					tmpHtmlInputCheckBox=new HtmlInputCheckBox();
					tmpHtmlInputCheckBox.ID=SignatureCheckBox;
					oCell.Controls.Add(tmpHtmlInputCheckBox);
					oRow.Cells.Add(oCell);
				}
			}
		}

		private void Page_Load(object sender, System.EventArgs e)
		{
			if(IsPostBack)
			{
				HtmlInputRadioButton
					tmpHtmlInputRadioButton;

				HtmlInputText
					tmpHtmlInputText;

				HtmlInputCheckBox
					tmpHtmlInputCheckBox;

				string
					r=string.Empty;

				if((tmpHtmlInputRadioButton=FindControl(SignatureRadio+"1") as HtmlInputRadioButton)!=null)
				{
					if(r!=string.Empty)
						r+=Environment.NewLine;
					r+=SignatureRadio+"1.Checked="+tmpHtmlInputRadioButton.Checked.ToString();
				}
				if((tmpHtmlInputRadioButton=FindControl(SignatureRadio+"2") as HtmlInputRadioButton)!=null)
				{
					if(r!=string.Empty)
						r+=Environment.NewLine;
					r+=SignatureRadio+"2.Checked="+tmpHtmlInputRadioButton.Checked.ToString();
				}
				if((tmpHtmlInputText=FindControl(SignatureText) as HtmlInputText)!=null)
				{
					if(r!=string.Empty)
						r+=Environment.NewLine;
					r+=SignatureText+".Value="+tmpHtmlInputText.Value;
				}
				if((tmpHtmlInputCheckBox=FindControl(SignatureCheckBox) as HtmlInputCheckBox)!=null)
				{
					if(r!=string.Empty)
						r+=Environment.NewLine;
					r+=SignatureCheckBox+".Checked="+tmpHtmlInputCheckBox.Checked.ToString();
				}
			}
		}
не хочет выставлять checked у выбранного переключателя :( Хотя в Request'е есть, 4 example:

Key [4]=DynamicRadio
Value [0]=DynamicRadio2

Причем не хочет выставлять только при первом submit'е страницы - при последующих уже все нормально. Что надо еще покрутить-прикрутить? BTW, созданные аналогично <input type="text"...>, <input type="checkbox"...> заполняются на ура на любом по счету submit'е... И в PageLoad их значения видны... Такое впечатление, что когда после PageInit накатывается ViewState при первом submit'е, то не находятся radio... М.б. необходимо еще как-то сообщить, об их создании... Что то а-ля HandleNeeded()?..

P.S. Сорри за дубляж... Просто провел некоторые изыскания... Первый пост, IMHO, оказался малоинформативным, а рихтонуть его...
_________________
"Helo, word!" - 17 errors 56 warnings
...
Рейтинг: 0 / 0
17.11.2005, 14:09
    #33384145
Axeleron
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Dynamic <input type="radio">
Я полагаю, там баг с этим HtmlInputRadioButton. Если ставить ему свойство runat=server, перестает работать клиентский скрипт на onclick. Верно заметил автор, со всеми остальными html-контролами всё вроде нормально.
Я тоже намучался с подобной проблемой, плюнул и обрабатываю всё для radio на клиенте.
...
Рейтинг: 0 / 0
17.11.2005, 14:47
    #33384289
Ex_Soft
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Dynamic <input type="radio">
Axeleronплюнул и обрабатываю всё для radio на клиенте
Но для того, чтобы обрабатывать что-то на клиенте, ему, ведь, необходимо с сервера вернуть, то, что он выбрал. Кроме как самому в PageLoad'е выискивать в Request'е значения radio, а затем, посредством FindControl'а искать и устанавливать необходимые Checked'ы - я пока другого пути решения данной проблемы не вижу
(Причем это необходимо делать только при первом submit'е страничке - тоже лишний менингит на предмет отслеживания этого) Мо есть еще какие-нить варианты-предложения?
_________________
"Helo, word!" - 17 errors 56 warnings
...
Рейтинг: 0 / 0
17.11.2005, 14:53
    #33384319
Axeleron
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Dynamic <input type="radio">
У меня лично нет - сам на javascript'ах реализовал всё. Сам был бы рад узнать как бороться с этой заразой.
...
Рейтинг: 0 / 0
17.11.2005, 15:23
    #33384452
profil
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Dynamic <input type="radio">
посмотрел бегло - много текта, чесно сказать вникать лень...
я так понял вы динамически на клиенте добавляете радиокнопки? тогда извесная
проблема:

http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/name_2.asp The
NAME attribute cannot be set at run time on elements dynamically created
with the createElement method. To create an element with a name
attribute, include the attribute and value when using the createElement
method.


The following example shows how to set the NAME attribute on a dynamically
created A element.
Код: plaintext
1.
var oAnchor = document.createElement("<A 
NAME='AnchorName'></A>");




Posted via ActualForum NNTP Server 1.3
...
Рейтинг: 0 / 0
17.11.2005, 16:49
    #33384768
Ex_Soft
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Dynamic <input type="radio">
Вы правильно заметили, что рожаю я радиокнопки, мягко выражаясь, ректально

Переделал:
Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
	if(!(oCell=document.createElement("TD")))
		return;
	if(!(oRadio=document.createElement("INPUT")))
		return;
	oRadio.type="radio";
	oRadio.id="<%=SignatureRadio%>1";
	oRadio.name="<%=SignatureRadio%>";
	oRadio.value="<%=SignatureRadio%>1";
	oRadio.checked=true;
	oCell.appendChild(oRadio);
	oRow.appendChild(oCell);

	if(!(oCell=document.createElement("TD")))
		return;
	if(!(oRadio=document.createElement("INPUT")))
		return;
	oRadio.type="radio";
	oRadio.id="<%=SignatureRadio%>2";
	oRadio.name="<%=SignatureRadio%>";
	oRadio.value="<%=SignatureRadio%>2";
	oRadio.checked=false;
	oCell.appendChild(oRadio);
	oRow.appendChild(oCell);
Под Mozilla 1.7.8, Mozilla Firefox 1.0.5 создает нормально, а, вот, под IE 6.0.2800.1106+SP1 добавляет, но не ставит checked.

Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
	if(!(oCell=document.createElement("TD")))
		return;
	if(!(oRadio=document.createElement("<INPUT name='<%=SignatureRadio%>'>")))
		return;
	oRadio.type="radio";
	oRadio.id="<%=SignatureRadio%>1";
	oRadio.value="<%=SignatureRadio%>1";
	oRadio.checked=true;
	oCell.appendChild(oRadio);
	oRow.appendChild(oCell);

	if(!(oCell=document.createElement("TD")))
		return;
	if(!(oRadio=document.createElement("<INPUT name='<%=SignatureRadio%>'>")))
		return;
	oRadio.type="radio";
	oRadio.id="<%=SignatureRadio%>2";
	oRadio.value="<%=SignatureRadio%>2";
	oRadio.checked=false;
	oCell.appendChild(oRadio);
	oRow.appendChild(oCell);
Под Mozilla 1.7.8, Mozilla Firefox 1.0.5 не создает, а, вот, под IE 6.0.2800.1106+SP1 добавляет, но, опять же, не ставит checked.

При submit'е формы симптомы аналогичны: в Request'е есть, но в PageLoad'е Checked не видны.
_________________
"Helo, word!" - 17 errors 56 warnings
...
Рейтинг: 0 / 0
17.11.2005, 16:56
    #33384784
Ex_Soft
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Dynamic <input type="radio">
В догонку: конструкция а-ля
Код: plaintext
1.
oRadio=document.createElement("<input type=\"radio\" id=\"<%=SignatureRadio%> 2 \" name=\"<%=SignatureRadio%>\" value=\"<%=SignatureRadio%> 2 \">")
Ессесно, под Mozilla 1.7.8, Mozilla Firefox 1.0.5 не работает

_________________
"Helo, word!" - 17 errors 56 warnings
...
Рейтинг: 0 / 0
17.11.2005, 17:28
    #33384928
Ex_Soft
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Dynamic <input type="radio">
Да и проблема уже как таковая локализовалась:
При первом submit'е формы данные из ViewState о радиокнопках, созданных динамически (JS) на клиенте, не накатываются на радиокнопки, созданные динамически в OnPageInit на сервере (в OnPageLoad они не видны).
_________________
"Helo, word!" - 17 errors 56 warnings
...
Рейтинг: 0 / 0
17.11.2005, 17:49
    #33385020
Ex_Soft
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Dynamic <input type="radio">
BTW,
http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/createelement.asp
To insert any other kind of input element, first invoke createElement for input, then set the type property to the appropriate value in the next line of code.

Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
	if(!(oRadio=document.createElement("INPUT")))
	{
		alert("!Radio");
		return;
	}
	oRadio.type="radio";
	oRadio.name="<%=SignatureRadio%>";
	oRadio.value="<%=SignatureRadio%>1";
	oRadio.id="<%=SignatureRadio%>1";
	oRadio.checked=true;
	oCell.appendChild(oRadio);
	oRow.appendChild(oCell);

	if(!(oCell=document.createElement("TD")))
		return;
	if(!(oRadio=document.createElement("INPUT")))
	{
		alert("!Radio");
		return;
	}
	oRadio.type="radio";
	oRadio.name="<%=SignatureRadio%>";
	oRadio.value="<%=SignatureRadio%>2";
	oRadio.id="<%=SignatureRadio%>2";
	oRadio.checked=false;
	oCell.appendChild(oRadio);
	oRow.appendChild(oCell);
мало того, что не ставит checked=true для первой радиокнопки, их потом вообще нельзя за'check'ить

_________________
"Helo, word!" - 17 errors 56 warnings
...
Рейтинг: 0 / 0
18.11.2005, 13:36
    #33386781
profil
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Dynamic <input type="radio">
Ex_SoftДа и проблема уже как таковая локализовалась:
При первом submit'е формы данные из ViewState о радиокнопках, созданных динамически (JS) на клиенте, не накатываются на радиокнопки,
созданные динамически в OnPageInit на сервере (в OnPageLoad они не видны).осталось понять причину проблемы =))
я предполагаю, что причина в том, что динамически созданным на клиенте радиокнопкам не присваиваются имена (в этом можно убедиться,
если посмотреть при постбэке что содержиться в Request.Forms)
Соответственно, для решения проблемы необходима решить вопрос с именами, а остальное все само собой образуется.
Как это сделть - с ходу сказать не могу, но копать надо в этом направлении...


Posted via ActualForum NNTP Server 1.3
...
Рейтинг: 0 / 0
18.11.2005, 15:03
    #33387080
Ex_Soft
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Dynamic <input type="radio">
profil
я предполагаю, что причина в том, что динамически созданным на клиенте радиокнопкам не присваиваются имена (в этом можно убедиться, если посмотреть при постбэке что содержиться в Request.Forms) Соответственно, для решения проблемы необходима решить вопрос с именами, а остальное все само собой образуется.

Ex_Soft
Хотя в Request'е есть, 4 example:

Key [4]=DynamicRadio
Value [0]=DynamicRadio2


no comment...

В общем, не знаю - правлильно ли, но заборол следующим образом:
Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
private void Page_Init(object sender, System.EventArgs e)
{
   if(IsPostBack)
   {
      ...
      tmpHtmlInputRadioButton.Load+=new EventHandler(tmpHtmlInputRadioButton_Load);
      ...
   }
}
		private void tmpHtmlInputRadioButton_Load(object sender, EventArgs e)
		{
			HtmlInputRadioButton
				tmpHtmlInputRadioButton;

			if((tmpHtmlInputRadioButton=sender as HtmlInputRadioButton)==null)
				return;

			string[]
				Value;

			if((Value=Request.Params.GetValues(tmpHtmlInputRadioButton.Name))!=null
				&& Value.Length!= 0 
				&& Server.HtmlEncode(Value[ 0 ])==tmpHtmlInputRadioButton.ID
				&& !tmpHtmlInputRadioButton.Checked)
			tmpHtmlInputRadioButton.Checked=true;
		} 
Все работает... По крайней мере так, как мне хочеться
Или это кривое решение?..
_________________
"Helo, word!" - 17 errors 56 warnings
...
Рейтинг: 0 / 0
Форумы / ASP.NET [игнор отключен] [закрыт для гостей] / Dynamic <input type="radio"> / 13 сообщений из 13, страница 1 из 1
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]