|
.net
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
checkbox problemOnPreRender if I add this...
Me.Attributes.Add("onmousedown", "alert(this.checked)") I get 'undefined', at least in IE. Everywhere I look "checked" is supposed to be the property to retreive the value of a checkbox... obviously I've missed something. Someone want to give me a clue? Thanks, Paul > Everywhere I look "checked" is supposed 'checked' is the correct property, and should work on any version of IE> to be the property to retreive the value of a checkbox... obviously I've > missed something. Someone want to give me a clue? Show quote >3. It might help if you posted a bit more of the relevant source code [and also check the HTML from 'View Source']. Also, see what 'this' is set to - if it's undefined itself, then IE is probably being silly; you could try something like getElementByID(...) to get a reference to the object. But 'this' should work... Paul,
Is this a checkbox list or a single checkbox? If it's a list then you have to specify which item in the list to check. Another difficulty is the way .NET renders the list using columns. Here's a script I wrote as part of a CheckBoxList Validator I created: Dim StringBuilder As New Text.StringBuilder StringBuilder.Append("<script language=""javascript"">" & vbCrLf) StringBuilder.Append("<!--" & vbCrLf) StringBuilder.Append("function checkboxlist_verification(clientID) {" & vbCrLf) StringBuilder.Append("var val = document.all[document.all[clientID].controltovalidate];" & vbCrLf) StringBuilder.Append("var col = val.all;" & vbCrLf) StringBuilder.Append("if (col != null ) {" & vbCrLf) StringBuilder.Append("var checked = 0;" & vbCrLf) StringBuilder.Append("var checkboxcount = 0;" & vbCrLf) StringBuilder.Append("for (i = 0; i < col.length; i++ ) {" & vbCrLf) StringBuilder.Append("if (col.item(i).tagName == 'INPUT') {" & vbCrLf) StringBuilder.Append("checkboxcount += 1;" & vbCrLf) StringBuilder.Append("if (col.item(i).checked ) {" & vbCrLf) StringBuilder.Append("checked += 1;" & vbCrLf) StringBuilder.Append("if (checked == " & NumberOfCheckBoxesRequired & ") {" & vbCrLf) StringBuilder.Append("return true;" & vbCrLf) StringBuilder.Append("}" & vbCrLf) StringBuilder.Append("}" & vbCrLf) StringBuilder.Append("}" & vbCrLf) StringBuilder.Append("}" & vbCrLf) StringBuilder.Append("if (checked == checkboxcount) {" & vbCrLf) StringBuilder.Append("return true;" & vbCrLf) StringBuilder.Append("};" & vbCrLf) StringBuilder.Append("else {" & vbCrLf) StringBuilder.Append("return false;" & vbCrLf) StringBuilder.Append("}" & vbCrLf) StringBuilder.Append("}" & vbCrLf) StringBuilder.Append("}" & vbCrLf) StringBuilder.Append("-->" & vbCrLf) StringBuilder.Append("</script>" & vbCrLf) ClientScriptManager.RegisterClientScriptBlock(ScriptType, "CheckBoxListVerification", StringBuilder.ToString()) The component I created lets you specify how many checkboxes in a checkboxlist must be checked for the page to validate. If that's what you happen to be attempting you may download the component which is free and includes all source code from here: http://www.aboutfortunate.com/default.aspx?page=checkboxlistvalidatordemo -- Show quoteSincerely, S. Justin Gengo, MCP Web Developer / Programmer www.aboutfortunate.com "Out of chaos comes order." Nietzsche "PJ6" <nob***@nowhere.net> wrote in message news:%235qewQHGGHA.1396@TK2MSFTNGP11.phx.gbl... > OnPreRender if I add this... > > Me.Attributes.Add("onmousedown", "alert(this.checked)") > > I get 'undefined', at least in IE. Everywhere I look "checked" is supposed > to be the property to retreive the value of a checkbox... obviously I've > missed something. Someone want to give me a clue? > > Thanks, > Paul > I'll be damned but this morning it's working as expected. Yesterday it was
giving me 'undefined'. I have no idea why, probably my fault, something dumb. Par for the course. Paul -------- Public Class TestControl Inherits CheckBox Public Sub New() Me.Text = "1234" End Sub Protected Overrides Sub OnPreRender(ByVal e As System.EventArgs) Me.Attributes.Add("onclick", "alert(this.checked)") MyBase.OnPreRender(e) End Sub End Class Show quote "PJ6" <nob***@nowhere.net> wrote in message news:%235qewQHGGHA.1396@TK2MSFTNGP11.phx.gbl... > OnPreRender if I add this... > > Me.Attributes.Add("onmousedown", "alert(this.checked)") > > I get 'undefined', at least in IE. Everywhere I look "checked" is supposed > to be the property to retreive the value of a checkbox... obviously I've > missed something. Someone want to give me a clue? > > Thanks, > Paul > |
|||||||||||||||||||||||