Wrox Programmer Forums
|
Classic ASP Professional For advanced coder questions in ASP 3. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 16th, 2003, 10:45 AM
Authorized User
 
Join Date: Aug 2003
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default Client & Server Side Scripting Problem

Hi

I've got an asp page that I think is Client Side scripted, it has a treeview in it. So far I've managed to get the text boxes etc below the treeview to fill when the user click on the tree node. What I want to do now is to update the database with the changes the user has made when the click on a button. I can't seem to get this to work. The function UpdateUser is in another asp page which is included at the top - I've also tried putting this function in the treeview page. Can anyone help as its driving me crazy!?!



<html>
<head>
<LINK REL=stylesheet
HREF="xxxx.css"
TYPE="text/css">
<xml id="oXML"></xml>
<script language="JavaScript">

    function open_help() {

    window.open('help.htm', 'help', config='height=400,width=450,scrollbars=1')
    }

    function right(e) {

    if (navigator.appName == 'Netscape' && (e.which == 3 || e.which == 2))
    return false;
    else if (navigator.appName == 'Microsoft Internet Explorer' && (event.button == 2 || event.button == 3))
    {
    alert("You do not have permission to use the right-click button.");
    return false;
    }

    return true;
    }

    document.onmousedown=right;
    document.onmouseup=right;
    if (document.layers) window.captureEvents(Event.MOUSEDOWN);
    if (document.layers) window.captureEvents(Event.MOUSEUP);
    window.onmousedown=right;
    window.onmouseup=right;

    Help1= new Image(20,20)
    Help1.src = "graphics/question_off.gif"
    Help2 = new Image(20,20)
    Help2.src = "graphics/question_on.gif"

    function HelpSwapOut() {
        document.help_link.src = Help2.src; return true;
    }

    function HelpSwapBack() {
        document.help_link.src = Help1.src; return true;
    }

</script>
<script language="VBScript">
Dim rs
Sub PopulateSubTree(oTreeNode, oXMLNode)

    Dim oNewTreeNode
    Dim oXMLSubNode
    Dim new_key

    Const tvwChild = 4

    ' add the current node to the tree
    new_key = "_" & oXMLNode.selectSingleNode("@id").nodevalue
    set oNewTreeNode = TreeView1.Nodes.Add(oTreeNode.key, tvwChild,new_key, oXMLNode.selectSingleNode("@name").nodeValue)

    ' recursively call the sub to add any children
    for each oXMLSubNode in oXMLNode.selectNodes("user")
        Call PopulateSubTree(oNewTreeNode, oXMLSubNode)
    next

    oNewTreeNode.Expanded = true

End Sub

Function PopulateTree()

    Dim oRoot

    with oXML.XMLDocument
        .async = false
        if .load("el_supremo.xml") Then
            set oRoot = TreeView1.Nodes.Add(,,"_-1","XXXX")
            oRoot.Expanded = true
            call PopulateSubTree(oRoot, oXML.SelectSingleNode("/xml/user"))
        else
            msgbox "Couldn't load xml file because " & .parseError.reason
        End if
    end with

    DisableUserDetails

End Function

Sub Treeview1_NodeClick(Node)
    dim sUser, iUser, iTeam, sEmail, iEntitlement, sLogon, iAdmin, iCorpTitle, iManager, sStartDate
    Dim oUserNode,x
    Dim arrUser

    Treeview1.SelectedItem.Expanded = true

    if Treeview1.SelectedItem.Text <> "XXXX" and Treeview1.SelectedItem.Text <> "XXXX" then

        iUser = right(TreeView1.SelectedItem.key,len(TreeView1.Sel ectedItem.Key) -1)

        Set oUserNode = oXML.selectSingleNode("/xml//.[@id=" & iUser & "]")

        sUser = oUserNode.selectSingleNode("@name").nodeValue
        iTeam = oUserNode.selectSingleNode("@team_id").nodeValue
        sEmail = oUserNode.selectSingleNode("@email").nodeValue
        iEntitlement = oUserNode.selectSingleNode("@entitlement").nodeVal ue
        sLogon = oUserNode.selectSingleNode("@logon").nodeValue
        iAdmin = oUserNode.selectSingleNode("@administrator").nodeV alue
        iCorpTitle = oUserNode.selectSingleNode("@corp_title").nodeValu e
        iManager = oUserNode.selectSingleNode("@manager_id").nodeValu e
        sStartDate = oUserNode.selectSingleNode("@start_date").nodeValu e

        arrUser = split(sUser,",")

        frmUser.txtlastname.value = trim(arrUser(0))
        frmUser.txtfirstname.value = trim(arrUser(1))
        frmUser.txtemail.value = sEmail
        frmUser.txtentitlement.value = iEntitlement
        frmUser.txtlogon.value = sLogon

        if iAdmin = 1 then
            frmUser.chkadmin.checked = True
        else
            frmUser.chkadmin.checked = False
        end if

        frmUser.cmbCorpTitle.value = iCorpTitle
        frmUser.cmbManager.value = iManager
        frmUser.cmbTeam.value = iTeam
        frmUser.txtstartdate.value = sStartDate
        frmUser.txtuser.value = iUser

    End if

End Sub

Sub EnableUserDetails()

    frmUser.txtlastname.disabled = false
    frmUser.txtfirstname.disabled = false
    frmUser.txtemail.disabled = false
    frmUser.txtentitlement.disabled = false
    frmUser.txtlogon.disabled = false
    frmUser.chkadmin.disabled = false
    frmUser.cmbCorpTitle.disabled = false
    frmUser.cmbManager.disabled = false
    frmUser.cmbTeam.disabled = false
    frmUser.txtstartdate.disabled = false

End Sub

Sub SaveUser()

    dim sLastName, sFirstName, iUser, iTeam, sEmail, iEntitlement, sLogon, iAdmin, iCorpTitle, iManager, sStartDate

    sLastName = frmUser.txtlastname.value
    sFirstName = frmUser.txtfirstname.value
    iCorpTitle = frmUser.cmbCorpTitle.value
    iManager = frmUser.cmbManager.value
    sEmail = frmUser.txtemail.value
    sLogon = frmUser.txtlogon.value
    sStartDate = frmUser.txtstartdate.value
    iEntitlement = frmUser.txtentitlement.value
    iTeam = frmUser.cmbTeam.value
    iUser = frmUser.txtuser.value
    if frmUser.chkadmin.value = true then
        iAdmin = 1
    else
        iAdmin = 0
    end if

    UpdateUser iUser


End Sub

</script>
</head>
<body onload="VBScript:PopulateTree">
<SCRIPT language=JavaScript src="jscript/admin_menu_array.js" type=text/javascript></SCRIPT>
<SCRIPT language=JavaScript src="jscript/mmenu.js" type=text/javascript></SCRIPT>
<table height="25" border="0" cellpadding="0" cellspacing="0" width="600">
<tr align="left">
<B></B><td align="left" bgcolor="#333366"><IMG align=bottom border=0 src="graphics/lion81x21whiteonblue.gif"></td>
<td align="right" bgcolor="#333366"><b> &nbsp;</b></td></tr>
</table>
<br>
<br>
<br>
<br>
<table width="600" border="0">
<tr>
    <td>Team Structure</td>
    <td align="right">
        <a href="javascript:open_help()" onMouseOver="HelpSwapOut()" onMouseOut="HelpSwapBack()"><IMG name="help_link" align="right" border=0 src="graphics/question_off.gif"></a>
    </td>
</tr>
</table>
<BR>
<OBJECT classid="clsid:C74190B6-8589-11D1-B16A-00C0F0283628" height=345 id=TreeView1
    style="FONT-FAMILY: tahoma; FONT-SIZE: 11px; FONT-STYLE: normal; FONT-VARIANT: normal; FONT-WEIGHT: normal; HEIGHT: 345px; LEFT: 0px; TOP: 0px; WIDTH: 600px"
    width=600>
    <PARAM NAME="_ExtentX" VALUE="15875">
    <PARAM NAME="_ExtentY" VALUE="9128">
    <PARAM NAME="_Version" VALUE="393217">
    <PARAM NAME="HideSelection" VALUE="0">
    <PARAM NAME="Indentation" VALUE="741">
    <PARAM NAME="LabelEdit" VALUE="1">
    <PARAM NAME="LineStyle" VALUE="0">
    <PARAM NAME="PathSeparator" VALUE="\">
    <PARAM NAME="Sorted" VALUE="1">
    <PARAM NAME="Style" VALUE="6">
    <PARAM NAME="Checkboxes" VALUE="0">
    <PARAM NAME="FullRowSelect" VALUE="0">
    <PARAM NAME="HotTracking" VALUE="0">
    <PARAM NAME="Scroll" VALUE="1">
    <PARAM NAME="SingleSel" VALUE="0">
    <PARAM NAME="ImageList" VALUE="">
    <PARAM NAME="BorderStyle" VALUE="1">
    <PARAM NAME="Appearance" VALUE="1">
    <PARAM NAME="MousePointer" VALUE="0">
    <PARAM NAME="Enabled" VALUE="1">
    <PARAM NAME="OLEDragMode" VALUE="0">
    <PARAM NAME="OLEDropMode" VALUE="0"></OBJECT>
<BR>
<BR>
<table width=600 cellpadding=0 cellspacing=0>
<tr>
    <td width=500>
        <table width =500 cellpadding=0 cellspacing=0>
        <form name="frmUser" method="post" action="admin_user.asp">
            <tr>
                <td width=150>First Name:</td>
                <td><input type="text" name="txtfirstname"></td>
            </tr>
            <tr>
                <td width=150>Last Name:</td>
                <td><input type="text" name="txtlastname"></td>
            </tr>
            <tr>
                <td width=150>Corporate Title:</td>
                <td><select name='cmbCorpTitle'>
                    <%

                    set rs = Server.CreateObject("ADODB.Recordset")

                    set rs = ListCorpTitles()

                    do while not rs.EOF
                        if rs("corporate_title") = "employee" then
                            Response.Write "<option value='" & rs("corporate_title_id") & "' selected>" & rs("corporate_title") & "</option>"
                        else
                            Response.Write "<option value='" & rs("corporate_title_id") & "'>" & rs("corporate_title") & "</option>"
                        end if
                        rs.Movenext
                    loop
                    rs.Close

                    set rs = nothing
                    set cmd = nothing

                    %>
                </select></td>
            </tr>
            <tr>
                <td width=150>Line Manager:</td>
                <td><select name='cmbManager'>
                    <%

                    set rs = Server.CreateObject("ADODB.Recordset")

                    set rs = ListUsers()

                    do while not rs.EOF
                        if rs("user_id") = 0 then
                            Response.Write "<option value='" & rs("user_id") & "' selected>" & rs("last_name") & ", " & rs("first_name") & "</option>"
                        else
                            Response.Write "<option value='" & rs("user_id") & "'>" & rs("last_name") & ", " & rs("first_name") & "</option>"
                        end if
                        rs.Movenext
                    loop
                    rs.Close

                    set rs = nothing
                    set cmd = nothing

                    %>
                </select></td>
            </tr>
            <tr>
                <td width=150>Team:</td>
                <td><select name='cmbTeam'>
                    <%

                    set rs = Server.CreateObject("ADODB.Recordset")

                    set rs = ListTeams()

                    do while not rs.EOF
                        Response.Write "<option value='" & rs("team_id") & "'>" & rs("team_name") & "</option>"
                        rs.Movenext
                    loop
                    rs.Close

                    set rs = nothing
                    set cmd = nothing

                    %>
                </select></td>
            </tr>
            <tr>
                <td width=150>Email Address:</td>
                <td><input type="text" name="txtemail" size="30"></td>
            </tr>
            <tr>
                <td width=150>NT Logon:</td>
                <td><input type="text" name="txtlogon"></td>
            </tr>
            <tr>
                <td width=150>Start Date:</td>
                <td><input type="text" name="txtstartdate"></td>
            </tr>
            <tr>
                <td width=150>Leave Entitlement:</td>
                <td><input type="text" name="txtentitlement"></td>
            </tr>
            <tr>
                <td width=150>Administrator:</td>
                <td><input type="checkbox" name="chkadmin"></td>
            </tr>
            <tr>
                <td colspan="2"><input type="text" name="txtuser"></td>
            </tr>
        </form>
        </table>
    </td>
    <td width=100>
        <table width =100 cellpadding=0 cellspacing=0>
            <tr>
                <td>
                    <table width= 100 cellspacing=0 cellpadding=0>
                        <tr>
                            <td>
                                <input type="image" src="graphics/edit.gif" border="0" onclick="EnableUserDetails()" name="imgEdit">&nbsp;&nbsp;
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <input type="image" src="graphics/save.gif" border="0" onclick="SaveUser()" name="imgSave">
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
        </table>
    </td>
</tr>
</table>
</body>
</html>

*****


Function UpdateUser(iUser)

        dim cmd, strConnect

    set cmd = Server.CreateObject("ADODB.Command")

    strConnect = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=True;Initial Catalog=XXXX;Data Source=XXXXXXXX"
    cmd.ActiveConnection = strConnect

        cmd.CommandText = "update_user"
        cmd.CommandType = adCmdStoredProc

        Set prm = cmd.CreateParameter("@manager_id", adInteger, adParamInput, 10,iUser)
        cmd.Parameters.Append prm

        cmd.Execute

        set cmd = nothing

End Function






Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem Converting Client-side to Server-side Code kwilliams ASP.NET 2.0 Professional 1 November 21st, 2007 05:25 PM
Firing server side events at client side codes mehdi62b ASP.NET 1.0 and 1.1 Basics 6 May 18th, 2005 09:11 AM
sharing a server-side variable with client-side pigtail Javascript How-To 6 November 4th, 2004 02:01 AM
Client side scripting Kaustav BOOK: Beginning ASP 3.0 1 November 7th, 2003 02:10 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.