Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Saving values in a disabled checkbox
Message
De
04/09/2013 17:45:16
 
 
À
04/09/2013 17:27:59
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Versions des environnements
Environment:
VB 9.0
OS:
Windows Server 2012
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01582105
Message ID:
01582214
Vues:
25
Hi Craig -
I understand that the disabled items technically do not exist and no values are submitted for them. What I don't understand is that this being the case, where is the call coming from to update the fields displayed in the disabled checkboxes (see my code).
Thanks


>Values of disabled objects are not sent back as part of the Submit. It's in the standard. Could this be the problem?
>
>>OK - Let's do this a little more basic. I removed the checkboxes from the formview and just placed them on the page. They are not bound to anything. They are populated with this routine.
>>
>>Private Sub Page_PreRenderComplete(sender As Object, e As System.EventArgs) Handles Me.PreRenderComplete
>>					
>>			Dim Basecase_ck As CheckBox = Basecase_CheckBox
>>			Dim Scenario1_ck As CheckBox = Scenario1_CheckBox
>>			Dim Scenario2_ck As CheckBox = Scenario2_CheckBox
>>			Dim Scenario3_ck As CheckBox = Scenario3_CheckBox
>>			Dim Scenario4_ck As CheckBox = Scenario4_CheckBox
>>			Dim Scenario5_ck As CheckBox = Scenario5_CheckBox
>>			Dim Scenario6_ck As CheckBox = Scenario6_CheckBox
>>
>>			If Not User.IsInRole("CanEditBasecase") Then
>>				Basecase_ck.Enabled = False
>>			End If
>>			If Not User.IsInRole("CanEditScenario1") Then
>>				Scenario1_ck.Enabled = False
>>			End If
>>			If Not User.IsInRole("CanEditScenario2") Then
>>				Scenario2_ck.Enabled = False
>>			End If
>>			If Not User.IsInRole("CanEditScenario3") Then
>>				Scenario3_ck.Enabled = False
>>			End If
>>			If Not User.IsInRole("CanEditScenario4") Then
>>				Scenario4_ck.Enabled = False
>>			End If
>>			If Not User.IsInRole("CanEditScenario5") Then
>>				Scenario5_ck.Enabled = False
>>			End If
>>			If Not User.IsInRole("CanEditScenario6") Then
>>				Scenario6_ck.Enabled = False
>>			End If
>>
>>			Dim oConn As New SqlConnection(ConfigurationManager.ConnectionStrings("sqlRTPConnectionString").ConnectionString)
>>			Dim oCommand As New SqlClient.SqlCommand("SELECT rtp_id, [basecase], scenario1, scenario2, scenario3, scenario4, scenario5, scenario6 FROM rtp_projects WHERE rtp_id = @rtp_id", oConn)
>>			oConn.Open()
>>			oCommand.Parameters.AddWithValue("@rtp_id", FormView1.SelectedValue)
>>			Dim oReader As SqlDataReader = oCommand.ExecuteReader
>>			oReader.Read()
>>			Basecase_ck.Checked = oReader("Basecase")
>>			Scenario1_ck.Checked = oReader("Scenario1")
>>			Scenario2_ck.Checked = oReader("Scenario2")
>>			Scenario3_ck.Checked = oReader("Scenario3")
>>			Scenario4_ck.Checked = oReader("Scenario4")
>>			Scenario5_ck.Checked = oReader("Scenario5")
>>			Scenario6_ck.Checked = oReader("Scenario6")
>>
>>			oReader.Close()
>>			oCommand.Dispose()
>>			oConn.Close()
>>			End Sub
>>
>>and updated with this:
>>
>>	Public Sub SaveCheckBoxes(sender As Object, e As EventArgs)
>>		Dim oConn As New SqlConnection(ConfigurationManager.ConnectionStrings("sqlRTPConnectionString").ConnectionString)
>>		Dim oCommand As New SqlClient.SqlCommand("", oConn)
>>		oConn.Open()
>>
>>		Select Case sender.ID.ToString
>>			Case "Basecase_CheckBox"
>>				oCommand.CommandText = "UPDATE [rtp_projects] SET [basecase] = @basecase WHERE rtp_id = @rtp_id"
>>				oCommand.Parameters.AddWithValue("@basecase", sender.Checked)
>>				oCommand.Parameters.AddWithValue("@RTP_ID", FormView1.SelectedValue)
>>			Case "Scenario1_CheckBox"
>>				oCommand.CommandText = "UPDATE [rtp_projects] SET [Scenario1] = @Scenario1 WHERE rtp_id = @rtp_id"
>>				oCommand.Parameters.AddWithValue("@Scenario1", sender.Checked)
>>				oCommand.Parameters.AddWithValue("@RTP_ID", FormView1.SelectedValue)
>>			Case "Scenario2_CheckBox"
>>				oCommand.CommandText = "UPDATE [rtp_projects] SET [Scenario2] = @Scenario2 WHERE rtp_id = @rtp_id"
>>				oCommand.Parameters.AddWithValue("@Scenario2", sender.Checked)
>>				oCommand.Parameters.AddWithValue("@RTP_ID", FormView1.SelectedValue)
>>			Case "Scenario3_CheckBox"
>>				oCommand.CommandText = "UPDATE [rtp_projects] SET [Scenario3] = @Scenario3 WHERE rtp_id = @rtp_id"
>>				oCommand.Parameters.AddWithValue("@Scenario3", sender.Checked)
>>				oCommand.Parameters.AddWithValue("@RTP_ID", FormView1.SelectedValue)
>>			Case "Scenario4_CheckBox"
>>				oCommand.CommandText = "UPDATE [rtp_projects] SET [Scenario4] = @Scenario4 WHERE rtp_id = @rtp_id"
>>				oCommand.Parameters.AddWithValue("@Scenario4", sender.Checked)
>>				oCommand.Parameters.AddWithValue("@RTP_ID", FormView1.SelectedValue)
>>			Case "Scenario5_CheckBox"
>>				oCommand.CommandText = "UPDATE [rtp_projects] SET [Scenario5] = @Scenario5 WHERE rtp_id = @rtp_id"
>>				oCommand.Parameters.AddWithValue("@Scenario5", sender.Checked)
>>				oCommand.Parameters.AddWithValue("@RTP_ID", FormView1.SelectedValue)
>>			Case "Scenario6_CheckBox"
>>				oCommand.CommandText = "UPDATE [rtp_projects] SET [Scenario6] = @Scenario6 WHERE rtp_id = @rtp_id"
>>				oCommand.Parameters.AddWithValue("@Scenario6", sender.Checked)
>>				oCommand.Parameters.AddWithValue("@RTP_ID", FormView1.SelectedValue)
>>
>>		End Select
>>
>>		oCommand.ExecuteNonQuery()
>>		oCommand.Dispose()
>>		oConn.Close()
>>		'MsgBox("Updated")
>>
>>	End Sub
>>
>>Each checkbox looks like this:
>>
>><asp:CheckBox ID="Basecase_CheckBox" runat="server" Enabled="true" Text="Basecase" OnCheckedChanged="SaveCheckBoxes" />
>>
>>This all works fine if all of the checkboxes are enabled. However, if a couple of them are disabled, as soon as I edit one of the remaining ones the status of the disabled ones goes to UnChecked and the table is updated to unchecked. I can't figure this out because there is NO binding and No call to the disabled checkboxes or their fields. I suspect it has something to do with viewstate but can't figure it out.
>>
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform