Solved

Message Box Display Data

Posted on 2010-11-15
4
515 Views
Last Modified: 2012-05-10
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 Explicit
Response.Expires = 0

Const section = "user"	

DIM objConn, objRS, strConnection, strQ
DIM assetID, X, userID, objRS2

Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open strConnection

Set objRS = Server.CreateObject("ADODB.Recordset")
Set objRS.ActiveConnection = objConn

Set objRS2 = Server.CreateObject("ADODB.Recordset")
Set objRS2.ActiveConnection = objConn

userID = 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 If


strQ =	"SELECT USERID,LASTNAME,FIRSTNAME,ACTIVE,ISPERSON, DEPARTMENTNUM " & _
		"FROM USERINFO " & _
		"ORDER BY ACTIVE DESC, LASTNAME"

'Response.Write strQ

objRS.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>&nbsp;</p>
                  </td>
                  <td> 
                    <p>&nbsp;</p>
                  </td>
                  <td> 
                    <p>&nbsp;</p>
                  </td>
                  <td> 
                    <p>&nbsp;</p>
                  </td>
                  <td> 
                    <p>&nbsp;</p>
                  </td>
                  
                    <td> 
                    <p>&nbsp;</p>
                  </td>
                </tr>
              </table>
            </div>
          </td>
        </tr>
      </table>
      <p align="center"> </p>
    </td>
  </tr>

</table>
</body>
</html>

<%
'clean up 
objRS.Close
objRS2.close
objConn.Close

Set objConn = nothing
Set objRS = nothing
Set objRS2 = nothing

FUNCTION 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 If
END FUNCTION

FUNCTION NullEmpty(varValue)
	If IsNull(varValue) Then
		NullEmpty = "NULL"
	ElseIf (varValue = "''") Or (varValue = "") Then
		NullEmpty = "NULL"
	Else
		NullEmpty = varValue
	End If
END FUNCTION
%>

Open in new window

0
Comment
Question by:fstinc
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 24

Accepted Solution

by:
DBAduck - Ben Miller earned 500 total points
ID: 34139491
If it were me, I would do the following:

Around these statements, I would set a flag to display an alert.
At the top of the page,
Dim blnShowAlert
blnShowAlert = false

Then....

  objRs.close
  Response.Write "Not deleted. " & t & " items found"
  blnShowAlert = true
End If

Then down in the code of the HTML after the body tag and where you would display the stuff, I would do this:

<% If blnShowAlert = true Then
Response.Write ("alert('Not deleted. " & t & " items found.'")
  End If
%>

Something like that.
0
 
LVL 93

Expert Comment

by:Patrick Matthews
ID: 34139532
On the client side, use MsgBox:

MsgBox "Message body", vbInformation, "Message box title"

Open in new window

0
 
LVL 18

Expert Comment

by:Rajar Ahmed
ID: 34142042
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 THEN
Response.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 code
objRS.MoveNext
Wend
%>

Open in new window

0
 

Author Comment

by:fstinc
ID: 34150384
How would I write javascript code in a vbscript and asp page?
0

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

627 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question