access checkbox populated in treeview - treeview

I am populating a treelist in the run-time. I want to add a checkbox to every leaf of the treelist. I am using the function below to populate the treeview and it works fine. but I am not able to access the checkbox
here is my code
Private Function GetChilds(ParentID As Integer) As String
Dim ChildsStr As String = ""
SQL = "Select Category_Name,Category_ID from Categories where Category_IsDeleted=0 and Category_ParentID=" & ParentID & " order by Category_Order"
Dim drx As SqlDataReader
drx = PF.ExecuteReader(SQL)
If drx.HasRows Then
ChildsStr += "<ul style='display: block'>" & vbNewLine
Do While drx.Read
Dim Ishavechd As Boolean = IsHaveChild(drx("Category_ID"))
If Ishavechd Then
ChildsStr += "<li class=""file-tree-folder open"">" & vbNewLine
Else
ChildsStr += "<li>" & vbNewLine
End If
ChildsStr += drx("Category_Name") & " "
If Not Ishavechd Then ChildsStr += " <input id='" & drx("Category_ID") & "' type='checkbox' />"
ChildsStr += GetChilds(drx("Category_ID"))
ChildsStr += "</li>" & vbNewLine
Loop
ChildsStr += "</ul>" & vbNewLine
End If
drx.Close()
Return ChildsStr
End Function
it populates good. and I am using this code to retrieve the checkbox value
Dim chk As HtmlControls.HtmlInputCheckBox = CType(Panel1.FindControl("8"), HtmlControls.HtmlInputCheckBox)
Response.Write(chk.Checked)
There is a checkbox with this id "8" I am sure of that.
I am adding the treeview to panel
<asp:Panel ID="Panel1" runat="server"></asp:Panel>
I am getting this error
Object reference not set to an instance of an object.
Please help.

I found a solution. I have added name attribute to the checkbox
<input name='" & drx("Category_ID") & "' id='" & drx("Category_ID") & "' type='checkbox' />
in the button click I used
Reques.form(checkbox name)

Related

Different output from same coding vb.net

im new here and want asking one question.
i have form with button that when clicked will fill database, but when im using keydown event the result is different.
here is the result, red box from click button and the green one from keydown event.
enter image description here
here is my code
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If TextBox1.Text = "" Or TextBox2.Text = "" Then
MsgBox("Masukan kode dan nama sub kelompok terlebih dahulu")
Else
For baris As Integer = 0 To DataGridView1.Rows.Count - 2
Dim inputsub As String = "insert into mastersubkelompok values('" & DataGridView1.Rows(baris).Cells(0).Value & "','" & DataGridView1.Rows(baris).Cells(1).Value & "','" & DataGridView1.Rows(baris).Cells(2).Value & "','" & TextBox1.Text & "')"
CMD = New OleDbCommand(inputsub, CONN)
CMD.ExecuteNonQuery()
MsgBox("Data berhasil di input")
Call kondisiawal()
Next
End If
End Sub
Private Sub SubKelompok_KeyDown(sender As Object, e As KeyEventArgs) Handles Me.KeyDown, DataGridView1.KeyDown
If e.KeyCode = Keys.F2 Then
If TextBox1.Text = "" Or TextBox2.Text = "" Then
MsgBox("Masukan kode dan nama sub kelompok terlebih dahulu")
Else
For baris As Integer = 0 To DataGridView1.Rows.Count - 2
Dim inputsub As String = "insert into mastersubkelompok values('" & DataGridView1.Rows(baris).Cells(0).Value & "','" & DataGridView1.Rows(baris).Cells(1).Value & "','" & DataGridView1.Rows(baris).Cells(2).Value & "','" & TextBox1.Text & "')"
CMD = New OleDbCommand(inputsub, CONN)
CMD.ExecuteNonQuery()
MsgBox("Data berhasil di input")
Call kondisiawal()
Next
End If
End If
End Sub

Classic asp posting login form no longer working

Working on a classic asp website I've notice a behavior that is causing a lot of trouble to some users. Somehow after a posting a Login Form some password are no longer going thru, getting error (104) reset connection by peer trying to access the main.asp .
Here is the weird thing that you guys can help me figure out:
After many hours trying to find a clue, we got it all back working just by changing the HTML name atribute from name="pwdSenha" to name="pwdTestSenha" then a day after it started all over again, so weve changed the name one more time, now its all working fine again but i guess just until tomorrow.
Is there an explanation for what's happening?
Here is the simplified code:
<form class="modal-content animate" id="frmLogin" name="frmLogin" method="post" action="../functions/aut_user.asp">
<div class="container">
<label><b>Login</b></label>
<input type="text" placeholder="Entre com Login" name="txtLogin" maxlength="45" required>
<label><b>Senha</b></label>
<input type="password" placeholder="Entre com a Senha" name="pwdSenha" maxlength="15">
<button id="bntLoginEntrar" type="submit">Entrar</button>
</div>
</form>
The Autentication class
<%
if funConectaBD() and Session("USER_ID") = "" then
Dim strLogin, strSenha
strLogin = fAspas(Request.Form("txtLogin"))
strSenha = "IS NULL"
if Trim(Request.Form("pwdSenha")) <> "" then
strSenha = "= '" & Cript(Request.Form("pwdSenha")) & "'"
end if
if strLogin <> "" then
'on error resume next
Dim adoRSLogin
Set adoRSLogin = Server.CreateObject("ADODB.Recordset")
adoRSLogin.ActiveConnection = bdConn
Dim strSQL
if Session("USER_CHANGE_PASS") <> "S" then
strSQL = "SELECT * " &_
"FROM users us" &_
"WHERE us.login = '" & strLogin & "' AND us.senha " & strSenha & " AND us.ativo = 'S';"
else
strSQL = "SELECT " &_
"FROM usuario us " &_
"WHERE us.login = '" & strLogin & "' AND us.ativo = 'S';"
end if
'Response.Write(strSQL & "<br/>")
'Response.End()
adoRSLogin.Open(strSQL)
if not adoRSLogin.EOF then
Session("USER_ID") = adoRSLogin("numero")
Session("FUNC_ID") = adoRSLogin("funcionario")
Session("USER_NAME") = adoRSLogin("nome")
Session("FUNC_NAME") = ""
Session("USER_LOGIN") = adoRSLogin("login")
Session("USER_EMAIL") = adoRSLogin("email")
Session("USER_PHONE") = adoRSLogin("telefone")
if adoRSLogin("adm") = "S" then
Session("USER_ADM") = TRUE
else
Session("USER_ADM") = FALSE
end if
Session("UNIT_ID") = adoRSLogin("unidade_numero")
Session("UNIT_NAME") = adoRSLogin("unidade_nome")
strSQL = "CALL inclui_conexao(" & Session("UNIT_ID") & "," & Session("USER_ID") & ",NOW(),NULL);"
'Response.Write(strSQL & "<br/>")
'Response.End
bdConn.execute(strSQL)
'on error goto 0
end if
strSQL = empty
set adoRSLogin = nothing
end if
end if
%>

Scheduling Conflict: can only detect conflict with exact time

This is the last problem I have to face in for my capstone project, and it's driving me nuts.
Basically, I have to be able to identify if Section/Faculty/Room are all in use when scheduling a subject, to avoid conflicts.
Here's what I've worked on, but so far it can only detect when Room is in use.
I can't figure out how to be able to prevent scheduling that's in-between time periods. For example: First entry would be 7-8:30AM. Second entry would be 7:30 AM to 9 AM. With the former existing, it should reject the latter but I can't figure out how to do that. This is what I've cooked up so far. How would you guys go about this?
Public Function DataInUse() As Boolean
Dim Temp As Boolean
Temp = False
If FacultyInUse() = True Then
MessageBox.Show("Faculty in use.")
cboFaculty.Focus()
DisplayFacultyInUse()
DisplayLabelConflictForFaculty()
Temp = True
ElseIf RoomInUse() = True Then
MessageBox.Show("Room in use.")
cboRoom.Focus()
DisplayRoomInUse()
DisplayLabelConflictForRoom()
Temp = True
End If
Return Temp
End Function
Public Function FacultyInUse() As Boolean
Dim com As New OleDbCommand(" Select * from qrySubjectOfferring Where cTimeIn >=#" & cboFrom.Text & "# and cTimeOut <=#" & cboTo.Text & "# and Faculty like'" & cboFaculty.Text & "%' and cDay Like '%" & cboDay.Text & "%'", clsCon.con)
Dim dr As OleDbDataReader = com.ExecuteReader()
dr.Read()
If dr.HasRows Then
Return True
Else
Return False
End If
End Function
Public Function RoomInUse() As Boolean
Dim com As New OleDbCommand("Select * from qryRoomAvailability WHERE (cTimeIn <=#" & cboFrom.Text & "# AND cTimeOut >=#" & cboFrom.Text & "# AND Room = '" & cboRoom.Text & "' AND cDay = '" & cboDay.Text & "') OR (cTimeIn <=#" & cboTo.Text & "# AND cTimeOut >=#" & cboTo.Text & "# AND Room = '" & cboRoom.Text & "' AND cDay = '" & cboDay.Text & "') OR (cTimeIn >= #" & cboFrom.Text & "# AND cTimeOut <= #" & cboTo.Text & "# AND Room = '" & cboRoom.Text & "' AND cDay = '" & cboDay.Text & "') ", clsCon.con)
Dim dr As OleDbDataReader = com.ExecuteReader()
dr.Read()
If dr.HasRows Then
Return True
Else
Return False
End If
End Function
Public Function SubjectAlreadyOffered(sSubject As String) As Boolean
Dim com As New OleDbCommand("Select * from qrySubjectOfferring Where Subject LIKE '%" & sSubject & "%'", clsCon.con)
Dim dr As OleDbDataReader = com.ExecuteReader()
dr.Read()
If dr.HasRows Then
Return True
Else
Return False
End If
End Function
Try simplifying your SQL to use Between clause and eliminate all entries where the From or To are in existing entries
In your RoomInUse() function
Dim strSQL as String
strSQL = "SELECT * FROM qryRoomAvailability WHERE " & _
" Room = '" & cboRoom.Text & "' AND cDay = '" & cboDay.Text & "'" & _
" AND NOT (#" & cboFrom.Text "# BETWEEN [" & cTimeIn & "] AND [" & cTimeOut & "])" & _
" AND NOT (#" & cboTo.Text "# BETWEEN [" & cTimeIn & "] AND [" & cTimeOut & "])"
Dim com As New OleDbCommand(strSQL, clsCon.con)

How can I reference a dynamically created ID in HTA (vbscript)?

See slimmed down code. I'm essentially creating a list of items (printers) along with a dynamically created unique radio button ID, and then I'd like to be able reference said Radio ID in order to toggle the Checked between True/False in Sub SetDefaultPrinter. Why? Because using Add Devices / Search is too hard for some of our users, hence, a cute little GUI. Why dynamic? Because I have multiple separate networks and I'd prefer the script to adjust itself as needed.
<html>
<head>
<title>My HTML application</title>
<HTA:APPLICATION
APPLICATIONNAME="My HTML application"
ID="MyHTMLapplication"
VERSION="1.0"/>
</head>
<script language="VBScript">
Public jj, strPrinters, strModels, strLocations
Sub Window_OnLoad
strPrinters = Array("Printer1", "Printer2")
strModels = Array("HP Color LaserJet 4525", "HP Color LaserJet 4525")
strLocations = Array("Room 1", "Room 2")
jj = UBound(strPrinters)
Call OnClickGo()
End Sub
Sub OnClickGo()
DataArea1.InnerHTML = ""
For i = 0 To jj
DataArea1.InnerHTML = DataArea1.InnerHTML & "<BR><font style=color:green;font-weight=bold;>" &_
"<input type=""" & "radio""" & " name=""" &_
strPrinters(i) & "Radio""" & " id=""" & "Radio" & i & """" &_
" title=""" & "Clicking here will set " & strPrinters(i) & " as default printer.""" &_
" onclick=""" & "SetDefaultPrinter(" & i & ")""" & " onmouseover=""" & "Pointer""" &_
" onmouseout=""" & "DefaultCursor""" & "></input>" &_
"<span id=""" & strPrinters(i) & "Span""" &_
" title=""" & "Click here delete printer mapping for " & strPrinters(i) & """" &_
" onmouseover=""" & "Pointer""" & " onmouseout=""" & "DefaultCursor""" &_
" onclick=""" & "OnClickDelete(" & i & ")""" &_
">" & strPrinters(i) & ", " & strModels(i) & ", Location: " & strLocations(i) & "</span></font>"
Next
End Sub
'========================================
'= Set Default Printer ==================
'========================================
Sub SetDefaultPrinter(ii)
DataArea2.InnerHTML = strPrinters(ii) & " would have been set as default if this was fully functional."
'
' Radio0 and Radio1 are dynamically created IDs, *really* want to somehow
' dynamically reference the dynamically created IDs.
' i.e. something like
' If ii <> 0 Then (Radio & ii).checked = False
'
If ii <> 0 Then Radio0.checked = False
If ii <> 1 Then Radio1.checked = False
End Sub
'========================================
'= Delete Printer Mapping ===============
'========================================
Sub OnClickDelete(ii)
DataArea2.InnerHTML = strPrinters(ii) & " would have been deleted if this was fully functional."
'Set wshnetwork = CreateObject("WScript.Network")
'wshnetwork.RemovePrinterConnection "\\SERVER\" & strPrinters(PrinterToDelete)
End Sub
'========================================
'= MOUSE Pointers =======================
'========================================
Sub Pointer
document.body.style.cursor = "hand"
End Sub
Sub DefaultCursor
document.body.style.cursor = "default"
End Sub
</script>
<body bgcolor="white">
<span id="DataArea1"></span>
<BR><BR><BR>
<span id="DataArea2"></span>
</body>
</html>
user2345916, I have modified your code where the variables pass like you wanted. I left your comments intact, so you can pick up where you left off. Hope this helps!
Basically, the answer to your problem lies within the button's "ID", "VALUE" and "ONCLICK" values.
The ONCLICK='SetDefaultPrinter(" & i & ")' will pass the looped number to the SubRoutine.
The SetDefaultPrinter(Radioii) sets a variable from the "ONCLICK" field of the button that sends you to that SubRoutine (In this case, it's a 0 or 1).
The "FileName = document.getElementById("Radio" & Radioii).value" gets the "VALUE" field of the button that matches the "ID" field that is set between the "()", which in your case is also the variable that was pulled from the ONCLICK.
From here, you can use (FileName) variable to do whatever you want (Match IF/THEN, etc)
<script language=vbscript>
Sub Window_OnLoad
window.resizeTo 500,300
strPrinters = Array("Printer 1", "Printer 2")
strModels = Array("HP Color LaserJet 4525", "HP Color LaserJet 4525")
strLocations = Array("Room 1", "Room 2")
jj = UBound(strPrinters)
For i = 0 To jj
strHTML1 = "<span id='Delete" & i & "' value='" & strPrinters(i) & "'title='Click here delete printer mapping for " & strPrinters(i) & "' onmouseover='Pointer' onmouseout='DefaultCursor' onclick='OnClickDelete(" & i & ")'> " & strPrinters(i) & " - " & strModels(i) & ", Location: " & strLocations(i) & "</span>"
strHTML2 = strHTML2 & "<input type='radio' name='radio' value='" & strPrinters(i) & "' id='Radio" & i & "' title='Clicking here will set " & strPrinters(i) & " as default printer.' onclick='SetDefaultPrinter(" & i & ")' onmouseover='Pointer' onmouseout='DefaultCursor'>" &_
"" & strHTML1 & "</input><br>"
DataArea1.InnerHTML = strHTML2
Next
End Sub
'========================================
'= Set Default Printer ==================
'========================================
Sub SetDefaultPrinter(Radioii)
FileName = document.getElementById("Radio" & Radioii).value
DataArea3.InnerHTML = Filename & " would have been set as default if this was fully functional."
'
' Radio0 and Radio1 are dynamically created IDs, *really* want to somehow
' dynamically reference the dynamically created IDs.
' i.e. something like
' If ii <> 0 Then (Radio & ii).checked = False
'
If Radioii = 0 Then Radio0 = False
If Radioii = 1 Then Radio1 = False
End Sub
'========================================
'= Delete Printer Mapping ===============
'========================================
Sub OnClickDelete(Deleteii)
RemoveName = document.getElementById("Delete" & Deleteii).value
DataArea3.InnerHTML = RemoveName & " would have been deleted if this was fully functional."
'Set wshnetwork = CreateObject("WScript.Network")
'wshnetwork.RemovePrinterConnection "\\SERVER\" & strPrinters(PrinterToDelete)
End Sub
'========================================
'= MOUSE Pointers =======================
'========================================
Sub Pointer
document.body.style.cursor = "hand"
End Sub
Sub DefaultCursor
document.body.style.cursor = "default"
End Sub
</script>

Hide one radio button option on ASP Classic page

I asked a few month back how to hide a few drop down option on a Classic ASP page which were being pulled from a database so that users could not select those options. But now on one of the remaining options there appear 3 radio box options. I have to remove one of those options. The option which I need to remove is called value="_BML7(B)" according to Chrome.
The last time I inserted the following code into the following code into the include.asp file which worked great but that was to hide drop down options. This I need to hide one radio button option from the current drop down options.
Sub buildDropDownList(strCurrentSelection, objListData, strCodeName, strDescriptionName, blnIncludeOther)
If Not objListData.BOF Then
objListData.MoveFirst
End If
Dim currentCodeValue
While Not objListData.EOF
currentCodeValue = objListData(strCodeName)
If (UCase(currentCodeValue)<>"_04GIDBM") And _
(UCase(currentCodeValue)<>"_05GIDFM") And _
(UCase(currentCodeValue)<>"_03MIS(Q") And _
(UCase(currentCodeValue)<>"_06GIDMS") And _
(UCase(currentCodeValue)<>"_08EXHRM") And _
(UCase(currentCodeValue)<>"_10EXMKT") And _
(UCase(currentCodeValue)<>"_12EXTTH") And _
(UCase(currentCodeValue)<>"_15AFT") And _
(UCase(currentCodeValue)<>"_16HSC") And _
(UCase(currentCodeValue)<>"_18LTD") And _
(UCase(currentCodeValue)<>"_19EBM") And _
(UCase(currentCodeValue)<>"_17EXHSC") Then
Response.Write "<option value='" & currentCodeValue & "' "
If StrComp(strCurrentSelection, currentCodeValue, 1) = 0 then
Response.Write "selected"
End If
Response.Write ">" & objListData(strDescriptionName) & "</option>" & VbCrLf
End If
I could really use the help on this and thank everyone in advance for their help! I not very good with Classic ASP but I'm trying.
Here is the code that I inserted last time on the include.asp file.
<p align="center">
<%
do until rsProgramLevel.EOF
Response.Write "<input type=""radio"" name=""programcode"" onclick=""onProgramCode()"" "
Response.Write "value=""" & rsProgramLevel("ProgramCode") & """ "
if rsProgramLevel("ProgramCode") = strProgramCode then
Response.Write "checked"
end if
Response.Write ">"
Response.Write " "
Response.Write rsProgramLevel("LevelDescription") & " (£" & FormatNumber(rsProgramLevel("ChargeValue"), 2) & ") "
Response.Write " "
rsProgramLevel.MoveNext
loop
%>
</p>
You could compile the list into a string, like so...
Const ignoreCodes = " _04GIDBM _05GIDFM _03MIS(Q _06GIDMS _08EXHRM _10EXMKT _12EXTTH _15AFT _16HSC _18LTD _19EBM _17EXHSC "
Add it to the very top of your file (after any Option Explicit commands). If you have new codes to add to it simply ensure that there's a space either side of it.
Then just test against it...
If Instr(ignoreCodes, UCase(currentCodeValue)) = 0 Then
Response.Write("<option value='" & currentCodeValue & "' ")
If StrComp(strCurrentSelection, " " & currentCodeValue & " ", 1) = 0 then
Response.Write " selected "
End If
Response.Write(">" & objListData(strDescriptionName) & "</option>")
End If
If you think about this further, then simply include the list in a redundant codes table in a database.
To make this simple, just wrap the code sending the HTML with a basic If..Then statement:
Dim currentCode
do until rsProgramLevel.EOF
currentCode = rsProgramLevel("ProgramCode")
If UCase(currentCode)<>"_BML7(B)" Then
Response.Write "<input type=""radio"" name=""programcode"" onclick=""onProgramCode()"" "
Response.Write "value=""" & currentCode & """ "
if rsProgramLevel("ProgramCode") = strProgramCode then
Response.Write "checked"
end if
Response.Write ">"
Response.Write " "
Response.Write rsProgramLevel("LevelDescription") & " (£" & FormatNumber(rsProgramLevel("ChargeValue"), 2) & ") "
Response.Write " "
End If
rsProgramLevel.MoveNext
loop

Resources