I currently have an ASP page that updates, deletes and displays assets of users. When you click on "Delete" button to delete a button, the page will check the database before deleting to make sure that they do not have assets. If they do, the delete statement will not execute, rather it will write the number of assets and asset name and description. I would like to display the "number of assets", "Name", and "Description" in a Message box rather than a Response.Write. Can this be done? If so, should I place code in client end or server end?
<%@ Language=VBScript %><%Option ExplicitResponse.Expires = 0Const section = "user" DIM objConn, objRS, strConnection, strQDIM assetID, X, userID, objRS2Set objConn = Server.CreateObject("ADODB.Connection")objConn.Open strConnectionSet objRS = Server.CreateObject("ADODB.Recordset")Set objRS.ActiveConnection = objConnSet objRS2 = Server.CreateObject("ADODB.Recordset")Set objRS2.ActiveConnection = objConnuserID = trim(Request.QueryString("userID")) IF Request.Form("Assets") = "Assets" THEN Response.Redirect("assetlist.asp?userid=" & userid & "") End IF IF userID <> "" THEN strQ = "UPDATE USERINFO SET " & _ " FIRSTNAME = " & SqlQuoteString(Request.Form("firstname")) & ", " & _ " LASTNAME = " & SqlQuoteString(Request.Form("lastname")) & ", " & _ " DEPARTMENTNUM = '" & Request.Form("department") & "', " & _ " ACTIVE = '" & Request.Form("active") & "', " & _ " ISPERSON = '" & Request.Form("isperson") & "'" & _ "WHERE USERID = '" & userid & "'" objConn.Execute (strQ) END IF If Trim(Request.Form("Delete")) = "Delete" Then strQ = "SELECT COUNT(*) as total FROM Assets as b" & _ " where b.userid = '" & userid & "'" objRS.open( strQ ) Dim t t=objRS.Fields("total") objRs.close if t=0 Then strQ = "DELETE a FROM userinfo as a LEFT JOIN Assets as b" & _ " on a.userID = b.userID" & _ " where b.assetid is null" & _ " and a.userid = '" & userid & "'" ObjConn.Execute (strQ) End If If t<>0 THEN strQ = "SELECT b.assetID, b.assetDescription FROM userinfo as a LEFT JOIN Assets as b" & _ " on a.userID = b.userID" & _ " where a.userid = '" & userid & "'" objRS.open( strQ ) While not objRS.EOF Response.Write objRS("assetID") & " Asset Description: " & objRS("assetDescription") & "<br>" objRS.Movenext Wend objRs.close Response.Write "Not deleted. " & t & " items found" End If End IfstrQ = "SELECT USERID,LASTNAME,FIRSTNAME,ACTIVE,ISPERSON, DEPARTMENTNUM " & _ "FROM USERINFO " & _ "ORDER BY ACTIVE DESC, LASTNAME"'Response.Write strQobjRS.Open(strQ)strQ = "SELECT DEPARTMENTID, DEPARTMENT FROM DEPARTMENT (NOLOCK)" objRS2.Open strQ'response.Write strq'response.end%><!-- #INCLUDE FILE = "nav.asp" --><HTML><body> </div> <div align="left"></div> <div align="left"><br> <br> </div> <div align="left"></div> <P><A href = "add_user.asp">Add new user</A></P> <P><A href = "temporary_user.asp">Temporary user</A></P> <% IF Request.QueryString("newuser") = "yup" THEN Response.Write "<CENTER><P><FONT COLOR = RED>New user Added</FONT></P></CENTER>" END IF %> <table width="800" border="1" cellspacing="0" cellpadding="0" bordercolor=#BBBBBB align="center"> <tr> <td bgcolor=<%=maincolor%> bordercolor="<%=maincolor%>"> <p align="center"><b><font color="#FFFFFF">User List/Edit</font></b></p> </td> </tr> <tr> <td height="89"> <div align="center"> <table width="100%" border="0" cellspacing="3" cellpadding="0"> <tr> <td width="16%"> <p>First</p> </td> <td width="16%"> <p>Last</p> </td> <td width="16%"> <p>Department</p> </td> <td width="14%"> <p>Active</p> </td> <td width="12%"> <p>Person</p> </td> <td width="26%"> <p>Save Changes</p> </td> </tr> <%X = 1 While not objRS.EOF %> <FORM method = "post" action = "temporary_user.asp?userid=<%=objRS("USERID")%>"> <tr> <td <%IF x mod 2 = 0 THEN Response.Write " bgcolor = #EEEEEE" END IF%>> <p> <Input type = text value = "<%=objRS("FIRSTNAME")%>" name=firstname> </p> </td> <td <%IF x mod 2 = 0 THEN Response.Write " bgcolor = #EEEEEE" END IF%>> <p> <Input type = text value = "<%=objRS("LASTNAME")%>" name=lastname> </p> </td> <td <%IF x mod 2 = 0 THEN Response.Write " bgcolor = #EEEEEE" END IF%>> <select name = "department" ID="Select2"> <%objRS2.movefirst%> <%While not objRS2.EOF %> <option value = <%=objRS2("DEPARTMENTID")%> <% If objRS2("DEPARTMENTID") = objRS("DEPARTMENTNUM") Then Response.Write (" selected") End If %> <font size="-1"> <% Response.Write objRS2("department")%> </font></option> <%objRS2.Movenext Wend%> </select> </td> <td <%IF x mod 2 = 0 THEN Response.Write " bgcolor = #EEEEEE" END IF%>> <p> <SELECT name = active> <OPTION value = "1" <%IF objRS("ACTIVE") = "True" THEN Response.Write " Selected" END IF%>>Yes</OPTION> <OPTION value = "0" <%IF objRS("ACTIVE") = "False" THEN Response.Write " Selected" END IF%>>No</OPTION> </SELECT> <%IF objRS("ACTIVE") = "False" THEN Response.Write "<FONT color = red>*</FONT>" END IF %> </p> </td> <td <%IF x mod 2 = 0 THEN Response.Write " bgcolor = #EEEEEE" END IF%>> <p> <SELECT name=isperson> <OPTION value = "1" <%IF objRS("ISPERSON") = "True" THEN Response.Write " Selected" END IF%>>Yes</OPTION> <OPTION value = "0" <%IF objRS("ISPERSON") = "False" THEN Response.Write " Selected" END IF%>>No</OPTION> </SELECT> <%IF objRS("ISPERSON") = "False" THEN Response.Write " <FONT color = red>*</FONT> " END IF %> </p> </td> <td <%IF x mod 2 = 0 THEN Response.Write " bgcolor = #EEEEEE" END IF%>> <p> <INPUT type = "Submit" name = "Update" value = "Update"> <INPUT type = "Submit" name = "Delete" value = "Delete" onclick="return confirm('Please verify user is not associated with any assets or user will not be deleted!');"> <INPUT type = "Submit" name = "Assets" value = "Assets"> </p> </td> </tr> </FORM> <%IF x mod 15 = 0 THEN %> <tr> </tr> <%END IF%> <% X=X+1 objRS.MoveNext Wend%> <tr> <td> <p> </p> </td> <td> <p> </p> </td> <td> <p> </p> </td> <td> <p> </p> </td> <td> <p> </p> </td> <td> <p> </p> </td> </tr> </table> </div> </td> </tr> </table> <p align="center"> </p> </td> </tr></table></body></html><%'clean up objRS.CloseobjRS2.closeobjConn.CloseSet objConn = nothingSet objRS = nothingSet objRS2 = nothingFUNCTION SQLQuoteString(ByVal strValue) Dim intPos If IsNull(strValue) Then SQLQuoteString = "NULL" Else For intPos = Len(strValue) To 1 Step -1 If Mid(strValue, intPos, 1) = "'" Then ' Insert extra "'" strValue = Left(strValue, intPos - 1) & "'" & Mid(strValue, intPos) End If Next SQLQuoteString = NullEmpty("'" & strValue & "'") End IfEND FUNCTIONFUNCTION NullEmpty(varValue) If IsNull(varValue) Then NullEmpty = "NULL" ElseIf (varValue = "''") Or (varValue = "") Then NullEmpty = "NULL" Else NullEmpty = varValue End IfEND FUNCTION%>
This can be simply done by javascript alert itself .
Follow these steps .
While retrieving data check the record hold assests or not
Maintain a boolean variable to check dat condn
Meeran 03
<%While not objRS.EOF'Your previous code IF x mod 2 = 0 THENResponse.Write " bgcolor = #EEEEEE"END IF%> <p><INPUT type = "Submit" name = "Update" value = "Update"><%'New Code *******************************'assestexists = ""assestexists = objRS("assestscolumn") ' you should have dis column in ur select query and according to value it comes u might know how to determine whether dat particular record holds assets or not if assestexists then 'Format this condition as u seperates records which has assets or Not%> <input type="button" text="alert" onclick="alert('<%=objRS("LASTNAME")&"has Assests"%>')"<%else%><INPUT type = "Submit" name = "Delete" value = "Delete" onclick="return confirm('Please verify user is not associated with any assets or user will not be deleted!');"><%end if '*********New Code ENDS*******************************''your previous codeobjRS.MoveNextWend%>
Open in new window