Re: Mystery Variable Change

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Ron (Ron_at_discussions.microsoft.com)
Date: 08/31/04


Date: Tue, 31 Aug 2004 10:15:16 -0700

Thanks for the response Hermit. Unfortunately you are speaking a little above
my head. Can you try that again a little slower? Thanks again.

"Hermit Dave" wrote:

> why change the global variable to modify the query. Have a global user class
> which reflects user add / edit / get info all the crap
>
> when the page is posted first check whether the user is an existing user
> editing their profile (i use viewstate to store the id but for user i would
> have the id in the authentication ticket.)
> you could then check the radiobuttonlist to see what was selected. if fact i
> wouldnt even do that... i would just do an update with original password
> again what the heck.
>
> Plus instead of using direct sql queries you could just use stored
> procedures.
>
> --
>
> Regards,
>
> Hermit Dave
> (http://hdave.blogspot.com)
> "Ron B" <Ron B@discussions.microsoft.com> wrote in message
> news:A3FAA5BB-5066-40D6-BAB5-B19E95419084@microsoft.com...
> > Hi,
> > I am gripping my mouse quite tightly b/c either I am blind or there is a
> > ghost in my cpu.
> >
> > Background: I am writing an Asp.net page that takes new user information
> > and
> > also doubles as a page for current users to edit their info. On the page
> > are
> > two PW boxes which a current user can disable or enable (using a
> > radiobuttonlist) depending on whether or not they want to change their
> > password while they are changing their other info. The radiobutton should
> > trigger the disabling/enabling of the two PW boxes as well as the
> > validation
> > on those boxes. It should also change a global boolean variable which will
> > determine how the Update statement will look (w/ or w/o the password
> > field.)
> >
> > Problem: Everything works fine except for the PassOn boolean variable
> > which
> > in turn effects whether the PW gets used in the Update command. I have
> > placed response.writes all over the place to determine why it doesn't work
> > to
> > no avail. It seems that somehow the variable, PassOn, gets changed to
> > false
> > all by itself when the page is loaded. I don't get it. Please help.
> >
> > Code:
> > <script runat="server">
> > dim FormTypeVar as string = "New"
> > dim strconnection as string = "myconnection"
> > dim objconnection as New SqlConnection(strConnection)
> > dim PassOn as boolean
> >
> > sub page_load (source as object, e as eventargs)
> >
> > FormType.text = "Enter New Employee"
> >
> > if len(session("empnum")) = 6 then
> > FormTypeVar = "Edit"
> > FormType.text = "Edit Personal Information"
> > else
> > emppass.enabled = true 'PW txtbox
> > empconfirm.enabled = true 'Confirm PW txtbx
> > pwvalid.enabled = true 'PW txtbx validation
> > end if
> > If (not ispostback) and (formtypevar = "Edit") then
> >
> > 'only place this var is changed in the page_load proc. should not be
> > triggered
> > '(and is not based on response.write) when radiobutton is changed
> > PassOn = false
> >
> > passchange.enabled = true 'radiobutton list
> > fill_page() 'fills page w/ user info
> > passchange.items(1).Selected=true
> > 'auto selects No
> > end if
> >
> > end sub
> >
> > sub submit_click (sender as object, e as eventargs)
> > If page.isvalid then
> > If FormTypeVar = "New" Then
> >
> > 'Enter new employee code
> >
> > Else
> >
> > dim PassString as string
> > if PassOn = true then
> > PassString = "emp_pass = '" & emppass.text & "', "
> > else
> > PassString = ""
> > end if
> > dim strSQL as String = "UPDATE employees " & _
> > "SET emp_num = '" & empnum.text & "', " & _
> > "emp_first = '" & empfirst.text & "', " & _
> > "emp_last = '" & emplast.text & "', " & _
> > "emp_title = '" & emptitle.text & "', " & _
> > "emp_dept = '" & empdept.text & "', " & _
> > "emp_site = '" & empsite.selecteditem.value & "', " & _
> > "emp_add = '" & empadd.text & "', " & _
> > "emp_work = '" & empwork.text & "', " & _
> > "emp_fax = '" & empfax.text & "', " & _
> > "emp_home = '" & emphome.text & "', " & _
> > "emp_email = '" & empemail.text & "', " & _
> > "emp_mgr = '" & empmgr.text & "', " & _
> > "emp_mgr_phone = '" & empmgrnum.text & "', " & _
> > PassString
> > " WHERE emp_id = " & session("empid")
> >
> > Connect()
> > dim dbComm as New SqlCommand(strSQL, objConnection)
> > dbcomm.executenonquery()
> > Disconnect()
> > response.Redirect("mainmenu.aspx")
> >
> > End if
> > End if
> > end sub
> >
> > sub togglepass(sender as object, e as eventargs)
> > dim temp as boolean = passchange.selecteditem.value
> > if temp then
> > PassOn = true
> > emppass.enabled = true
> > empconfirm.enabled = true
> > pwvalid.enabled = true
> > else
> > PassOn = false
> > emppass.enabled = false
> > empconfirm.enabled = false
> > pwvalid.enabled = false
> > end if
> > end sub
> >
> > sub password_validate(sender as object, args as servervalidateeventargs)
> > if PassOn = false then
> > args.isvalid=true
> > exit sub
> > end if
> > dim temp1, temp2 as string
> > temp1 = emppass.text
> > temp2 = empconfirm.text
> > if temp1 = "" or temp2 = "" then
> > args.isvalid = false
> > pwvalid.errormessage = "You must enter your new password twice."
> > exit sub
> > end if
> > if temp1 <> temp2 then
> > args.isvalid = false
> > else
> > args.isvalid = true
> > end if
> > end sub
> > </script>
> > <body>
> >
> > <!--Other asp.net controls, i.e. last name, first name etc.-->
> >
> > <asp:TextBox id="emppass" runat="server" textmode="password" Columns="25"
> > enabled="false"/>
> > <asp:CustomValidator
> > id="pwvalid"
> > OnServerValidate="password_validate"
> > errormessage="Your passwords did not match, please try again."
> > runat="server" Enabled="false">*</asp:customValidator>
> >
> > <asp:TextBox id="empconfirm" runat="server" textmode="password"
> > Columns="25"
> > enabled="false"/>
> >
> > Change your password?
> > <asp:RadioButtonList ID="passchange" Enabled="false" RepeatColumns="2"
> > OnSelectedIndexChanged="togglepass"
> > AutoPostBack="true" runat="server" >
> > <asp:ListItem Value=true Text="Yes" />
> > <asp:ListItem Value=false Text="No" />
> > </asp:RadioButtonList>
> > </body>
>
>
>


Quantcast