Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Problem looping through controls on a web
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Problem looping through controls on a web

 Post Reply Post Reply
Author
jamesb View Drop Down
Newbie
Newbie


Joined: 01 September 2003
Status: Offline
Points: 4
Post Options Post Options   Thanks (0) Thanks(0)   Quote jamesb Quote  Post ReplyReply Direct Link To This Post Topic: Problem looping through controls on a web
    Posted: 01 September 2003 at 7:20am

I'm trying to write a function that loops through all the controls on a web form, and puts the values entered by the user into a string, which will then be passed into the database using a stored procedure.

For some reason that I simply can't fathom, the stringbuilder class loses the string it contains at certain points during the cycle through the controls on the page. The page contains 5 panel objects, and the stringbuilder loses the values stored in it when the "GetControlValues" function moves from one panel to the next. Why would this be?

Hope I've explained this well enough - all code is below - can anyone suggest what I'm doing wrong? Thanks for any help :)

 

Public Function GetControlValues(s as Object, SqlStr As String) 
  
 Dim ctl As Control
 Dim ReturnValue As String
 Dim SqlStringProp As String
 Dim StringBuild As New Stringbuilder
 
 StringBuild.Append(SqlStr)
 response.write("<b>Stringbuilder BEFORE:</b> " & StringBuild.ToString())  <<--- Stringbuilder has a value here
 
 For each ctl in s.Controls
 
   response.write("<b>Stringbuilder DURING:</b> " & StringBuild.ToString()) <<-- But is empty here *only* at the begining of a new panel
   
   ReturnValue=ShowControlDetails(ctl)
 
   If Len(ReturnValue) > 0 Then
    
    StringBuild.Append(" '")
    StringBuild.Append(ReturnValue)
    StringBuild.Append("'") 
   
   Else
   
    response.write("<b>ReturnValue:</b> No value returned")
   
   End If
   
   response.write("<b>Stringbuilder AFTER:</b> " & StringBuild.ToString())  
 
   GetControlValues(ctl, SqlStringProp)
  
 Next

End Function

 

Public Function ShowControlDetails(ctlControl As Object)

   Dim SqlString As String
   
   Select Case ctlControl.GetType().ToString()
     
     Case "System.Web.UI.WebControls.TextBox"
     SqlString=ctlControl.Text.ToString()
     
     Case "System.Web.UI.WebControls.DropDownList"
     SqlString=ctlControl.SelectedItem.Text.ToString()
          
     Case Else
     response.write("<b>This control isn't relevant?</b>")
   End Select
   
   return SqlString

End Function

Back to Top
Diep-Vriezer View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 August 2003
Location: Netherlands
Status: Offline
Points: 831
Post Options Post Options   Thanks (0) Thanks(0)   Quote Diep-Vriezer Quote  Post ReplyReply Direct Link To This Post Posted: 01 September 2003 at 8:15am

You are declaring the strings within a sub. Why don't you try and declare all the strings with Public?

Public SqlString As String, ctl As Control, and so on.

Maybe this would work, but it seems like a relative easy problem to me, and I'm quite a n00b.

Gone..
Back to Top
jamesb View Drop Down
Newbie
Newbie


Joined: 01 September 2003
Status: Offline
Points: 4
Post Options Post Options   Thanks (0) Thanks(0)   Quote jamesb Quote  Post ReplyReply Direct Link To This Post Posted: 01 September 2003 at 10:04am

*doh*

yes - was staring me in the face all along - thanks for pointing it out

 

 



Edited by jamesb
Back to Top
Diep-Vriezer View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 August 2003
Location: Netherlands
Status: Offline
Points: 831
Post Options Post Options   Thanks (0) Thanks(0)   Quote Diep-Vriezer Quote  Post ReplyReply Direct Link To This Post Posted: 01 September 2003 at 2:30pm
lol
Gone..
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.