From: "Ken Cox [Microsoft MVP]" <
[email protected]>
References: <
[email protected]>
Subject: Re: radiobutton postback change event
Date: Wed, 21 Jan 2004 21:50:44 -0500
Lines: 61
MIME-Version: 1.0
Content-Type: text/plain;
format=flowed;
charset="Windows-1252";
reply-type=original
Content-Transfer-Encoding: 7bit
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2055
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2055
Message-ID: <
[email protected]>
Newsgroups: microsoft.public.dotnet.framework.aspnet
NNTP-Posting-Host: toronto-hse-ppp3665238.sympatico.ca 65.95.163.55
Path: cpmsftngxa07.phx.gbl!cpmsftngxa06.phx.gbl!cpmsftngxa09.phx.gbl!TK2MSFTNGP08.
phx.gbl!TK2MSFTNGP12.phx.gbl
Xref: cpmsftngxa07.phx.gbl microsoft.public.dotnet.framework.aspnet:204077
X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
Hi Dave,
This seems like a bit of a hack, but....
You could use client-side script to loop through the radio buttons and find
the one that is checked. When you find it, clear the value from the onclick
event so the postback won't happen.
There are probably better ways, but until that solution arrives, this might
get you going:
Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
Label1.Text = Now.ToLongTimeString
Dim sb As New System.Text.StringBuilder
sb.Append("<script language=javascript>")
sb.Append("for (var num=0; num < ")
sb.Append("document.forms[0].elements.length;num++)")
sb.Append("{")
sb.Append("if (document.forms[0].elements[num].checked==true)")
sb.Append("{")
sb.Append(" document.forms[0].elements[num].onclick='';")
sb.Append(" break;")
sb.Append("}")
sb.Append("}")
sb.Append("</script>")
Page.RegisterStartupScript("radchk", sb.ToString)
End Sub
<P>
<asp:RadioButton id="RadioButton1" runat="server" Text="Red"
GroupName="colours" AutoPostBack="True"></asp:RadioButton> </P>
<P>
<asp:RadioButton id="RadioButton2" runat="server" Text="Green"
GroupName="colours" AutoPostBack="True"
Checked="True"></asp:RadioButton></P>
<P>
<asp:RadioButton id="RadioButton3" runat="server" Text="Blue"
GroupName="colours" AutoPostBack="True"></asp:RadioButton></P>
<P>
<asp:Label id="Label1" runat="server"></asp:Label></P>
Ken
MVP [ASP.NET]
dave said:
I have half a dozen web form radio buttons on a web form. Each of them is
set to postback=true. However, if for instance radiobutton1 is already
selected and the user selects it again, it performs a postback.
I only want to do a postback if the value of the radiobutton is changed.
What is the best method to accomplish this?
thx
dave