Doubt radio

P

Paulo

Hi, I have a RadioButtonList and I need to do some verifications on a
"OnChange" event on client... because on classic asp/html I just add a
"onChange" event on <input type="radio" onChange="">, etc...

How can it be done on RadioButtonList server component on asp.net 2.0 C# VS
2005 ?

Thanks!
 
M

Mark Rae [MVP]

Hi, I have a RadioButtonList and I need to do some verifications on a
"OnChange" event on client... because on classic asp/html I just add a
"onChange" event on <input type="radio" onChange="">, etc...

How can it be done on RadioButtonList server component on asp.net 2.0 C#
VS 2005 ?

MyRadioButton.Attributes.Add("onchange", "alert('Hello!');");

By the way, I've noticed that you seem to title your posts "Doubt..." - what
do you actually mean by that...?
 
P

Paulo

Thanks for replying Mark, I´ll try what you said... sorry, maybe I have no
correct gramatical English, but what the word "doubt" mean in english??

in Brasil I learned the word "doubt" means we dont know anything... Am I
wrong?

sorry the bad english!
 
M

Mark Rae [MVP]

but what the word "doubt" mean in english??
dúvida

in Brasil I learned the word "doubt" means we dont know anything...

Doubt means to have difficulty believing that something is true...
 
P

Paulo

Mark, I did what you said, but the .net placed the onChange event on the
table generated by asp.net wich has the same name of the RadioButton... like
below:
<table id="radioSimNao" title="radioSimNao"
onchange="javascript:alert('teste')" border="0">

I think the onchange must be on <input> tag, dont you think?

Thanks!
 
M

Mark Rae [MVP]

Mark, I did what you said, but the .net placed the onChange event on the
table generated by asp.net wich has the same name of the RadioButton...

Ah - you need to give each of your controls unique names...
 
P

Paulo

Mark, the <table> below is generated automatically by .net, the radios
inputs are inside the <td>, as you can see the .net added _1, _2, _3 for
each id input, but the name is the same...

<table id="radioSimNao" title="radioSimNao"
onchange="javascript:alert('teste')" border="0">
<tr>
<td><input id="radioSimNao_0" type="radio" name="radioSimNao" value="S"
/><label for="radioSimNao_0">Aprovar</label></td><td><input
id="radioSimNao_1" type="radio" name="radioSimNao" value="N" /><label
for="radioSimNao_1">Rejeitar</label></td><td><input id="radioSimNao_2"
type="radio" name="radioSimNao" value="V" /><label
for="radioSimNao_2">Voltar p/ elaboração</label></td><td><input
id="radioSimNao_3" type="radio" name="radioSimNao" value="A"
checked="checked" /><label for="radioSimNao_3">Não alterar
status</label></td>
</tr>
</table>
 
M

Mark Rae [MVP]

Mark, the <table> below is generated automatically by .net, the radios
inputs are inside the <td>, as you can see the .net added _1, _2, _3 for
each id input, but the name is the same...

Please show the .NET code...
 
P

Paulo

protected void grdContratos_RowDataBound(object sender, GridViewRowEventArgs
e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.Cells[0].Controls != null)
{
RadioButtonList radioSimNao =
(RadioButtonList)e.Row.Cells[0].Controls[0].FindControl("radioSimNao");
radioSimNao.ToolTip = radioSimNao.ClientID;
radioSimNao.Attributes.Add("onchange", "javascript:alert('teste')");
}
}
}

What is the diference between RowCreated and RowDataBound ?
 
M

Mark Rae [MVP]

I haven't actually tried this, but I think you should be able to do
something like this:

RadioButtonList radioSimNao =
(RadioButtonList)e.Row.Cells[0].Controls[0].FindControl("radioSimNao");
foreach (ListItem li in radioSimNao.Items)
{
li.ToolTip = li.ClientID;
li.Attributes.Add("onchange", "alert('teste');");
}
What is the diference between RowCreated and RowDataBound ?

RowCreated occurs when a new row is created in the control, and RowDataBound
occurs when the data row is bound to data in the control.
 
P

Paulo

Mark, I tried, but the .net putted the onChange on each <span> tag... see
below:.. How can I put it just on <input> tag? Thanks!

<span onchange="alert('teste');"><input
id="ctl00_Contentplaceholder2_grdContratos_ctl02_radioSimNao_0" type="radio"
name="ctl00$Contentplaceholder2$grdContratos$ctl02$radioSimNao" value="S"
/><label
for="ctl00_Contentplaceholder2_grdContratos_ctl02_radioSimNao_0">Aprovar</label></span></td><td><span
onchange="alert('teste');"><input
id="ctl00_Contentplaceholder2_grdContratos_ctl02_radioSimNao_1" type="radio"
name="ctl00$Contentplaceholder2$grdContratos$ctl02$radioSimNao" value="N"
/><label
for="ctl00_Contentplaceholder2_grdContratos_ctl02_radioSimNao_1">Rejeitar</label></span></td><td><span
onchange="alert('teste');"><input
id="ctl00_Contentplaceholder2_grdContratos_ctl02_radioSimNao_2" type="radio"
name="ctl00$Contentplaceholder2$grdContratos$ctl02$radioSimNao" value="V"
/><label
for="ctl00_Contentplaceholder2_grdContratos_ctl02_radioSimNao_2">Voltar p/
elaboração</label></span></td><td><span onchange="alert('teste');"><input
id="ctl00_Contentplaceholder2_grdContratos_ctl02_radioSimNao_3" type="radio"
name="ctl00$Contentplaceholder2$grdContratos$ctl02$radioSimNao" value="A"
checked="checked" /><label
for="ctl00_Contentplaceholder2_grdContratos_ctl02_radioSimNao_3">Não alterar
status</label></span>

Mark Rae said:
I haven't actually tried this, but I think you should be able to do
something like this:

RadioButtonList radioSimNao =
(RadioButtonList)e.Row.Cells[0].Controls[0].FindControl("radioSimNao");
foreach (ListItem li in radioSimNao.Items)
{
li.ToolTip = li.ClientID;
li.Attributes.Add("onchange", "alert('teste');");
}
What is the diference between RowCreated and RowDataBound ?

RowCreated occurs when a new row is created in the control, and
RowDataBound occurs when the data row is bound to data in the control.
 
P

Paulo

Hey Mark, I replaced onchange to onclick and worked... I think there is no
onchange on radiobutton .net !!!

Thanks man!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top