Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Confirmation Popup on RadioButtonList

Status
Not open for further replies.

andrea96

Programmer
Jan 26, 2001
201
US
I am attempting to display a confirmation popup when the selected value of a radiobuttonlist is changed to a certain value, and only perform some statements if Ok is pressed. I get the popup to display, but the program processes the SelectedIndexChanged whether I press Ok or Cancel.

When I display my data record, I add the attribute if the radiobuttonlist is 1 value, as follows.
Code:
rblShipMethod.Attributes.Add("OnClick", "javascript:return confirm('Are you sure you want to change the shipping method?');")
I also tried "OnSelectedIndexChanged", but then the popup is not displayed at all.

I have AutoPostBack set to True for the radiobuttonlist. Here is my code for the SelectedIndexChanged of the radiobuttonlist.
Code:
Private Sub rblShipMethod_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rblShipMethod.SelectedIndexChanged
    Select Case rblShipMethod.SelectedValue
        Case "LTL"
            'Do something              
            rblShipMethod.Attributes.Clear()
        Case "Truckload"
            'Do something esle
            rblShipMethod.Attributes.Add("OnClick", "javascript:return confirm('Are you sure you want to change the shipping method?');")
    End Select
End Sub
What am I doing wrong?

Thanks,
Andrea
 
You are adding the attribute when the user selects the radio button (so it exists once they have clicked it but not before they click it).

You'll need to add it before they click it if you want it to fire when they do click it.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
I am initially adding the attribute when the record is first displayed, before they click the radiobuttonlist (The first piece of code). Then, I add or clear it based on the value of the radiobuttonlist (Second code). The popup is displaying when expected, but it is not preventing the selected value of the radiobuttonlist from being changed if Cancel is clicked on the popup.
Thanks,
Andrea
 
A radio button list renders as a table with rows/cells appropriate to the items in the datasource, with an html input of type="radio" for each item in the datasource. I.E., A radiobutton list bound to a datasource with three items, say LTL, Truckload and ANOther will actually render as something like;
Code:
<table id="rblShipMethod" border="0">
	<tr>
		<td><input id="rblShipMethod_0" type="radio" name="rblShipMethod" value="LTL" onclick="__doPostBack('rblShipMethod_0','')" language="javascript" /><label for="rblShipMethod_0">LTL</label></td>
	</tr><tr>
		<td><input id="rblShipMethod_1" type="radio" name="rblShipMethod" value="Truckload" onclick="__doPostBack('rblShipMethod_1','')" language="javascript" /><label for="rblShipMethod_1">Truckload</label></td>
	</tr><tr>
		<td><input id="rblShipMethod_2" type="radio" name="rblShipMethod" value="ANOther" checked="checked" onclick="__doPostBack('rblShipMethod_2','')" language="javascript" /><label for="rblShipMethod_2">ANOther</label></td>
	</tr>
</table>

This actually means that any attributes added to a radiobuttonlist actually get applied to the rendered table, not the radiobuttons collection making up the rendered radiobuttonlist wheras I assume you actually want the client side event applied to the Input control of type="radio".

Run your page and view the source when its running, you'll see what I mean.

Rhys
Gene Roddenberry was a legendary pioneer of thought-provoking, futuristic science fiction. George Lucas created Jar Jar Binks
 
Ok, I see what you mean. I tried the radiobuttonlist after I couldn't get radiobuttons to work. So, I tried radiobuttons again. I added the attribute in the load of the radiobutton.
Code:
Private Sub radLTL_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles radLTL.Load
    radLTL.Attributes.Add("OnClick", "javascript:return confirm('Are you sure you want to change the shipping method?');")
End Sub
And I can see it in the source when running the page.
Code:
<input id="radLTL" type="radio" name="ShipMethod" value="radLTL" onclick="javascript:return confirm('Are you sure you want to change the shipping method?');__doPostBack('radLTL','')" language="javascript" /><label for="radLTL">LTL</label>
<input id="radTruckload" type="radio" name="ShipMethod" value="radTruckload" checked="checked" onclick="__doPostBack('radTruckload','')" language="javascript" /><label for="radTruckload">Truckload</label>
However, with the radiobuttons, the page is not doing a postback when I click LTL, so my code in that radiobutton's CheckChanged is never being executed. Is there a way I can fix this?

Thanks,
Andrea
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top