CodeVerge.Net Beta


   Explore    Item Entry   Register  Login  
Microsoft News
Asp.Net Forums
IBM Software
Borland Forums
Adobe Forums
Novell Forums




Can Reply:  No Members Can Edit: No Online: Yes
Zone: > NEWSGROUP > Asp.Net Forum > windows_hosting.hosting_open_forum Tags:
Item Type: NewsGroup Date Entered: 9/22/2003 2:17:47 PM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
NR
XPoints: N/A Replies: 1 Views: 96 Favorited: 0 Favorite
2 Items, 1 Pages 1 |< << Go >> >|
toddhd
Asp.Net User
Have to click twice to submit - weird problem9/22/2003 2:17:47 PM

0

I am building a simple "file browser" page. It doesn't really do much yet - All I need it to do for now is browse up and down through the folders. The aspx page has a table with two cells - the left cell (cellFolders) holds the directory names, and the right cell (cellFiles) shows the file names. Easy-peasy.

So here is the problem. I load the page, and the files and folders show up as expected. I click on a folder name to browse that folder. A property called CurrentPath should have the folder added to it. For example, if the current path is "C:", and I click on a folder called "admin", then the current path should now be "C:\admin". Then everything should refresh and display.

What *is* happening is that I click on the "admin" folder, and the page reloads, but the CurrentPath doesn't change. If I click on "admin" a second time, then the page reloads, and the CurrentPath is now "C:\\admin".

I know this is some kind of issue in regards to the viewstate, or when the changes are getting picked up, but I just can't seem to get around it. Below is my code-behind. If anyone can clue me in, I'd appreciate it. - Thanks!

====================================
Imports System

Imports System.IO
Namespace DotNetNuke
Public Class FilePicker
Inherits DotNetNuke.BasePage
Public Property CurrentPath() As String
Get
Dim o As Object = Viewstate("CurrentPath")
If o Is Nothing Then
Return System.Web.HttpContext.Current.Request.PhysicalApplicationPath
'Viewstate("CurrentPath") = System.Web.HttpContext.Current.Request.PhysicalApplicationPath
Else
Return CStr(o)
End If
End Get

Set(ByVal Value As String)
Viewstate("CurrentPath") = Value
End Set
End Property
#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

End Sub
Protected WithEvents cellFolders As System.Web.UI.HtmlControls.HtmlTableCell
Protected WithEvents cellFiles As System.Web.UI.HtmlControls.HtmlTableCell
Protected WithEvents ImageButton1 As System.Web.UI.WebControls.ImageButton
Protected WithEvents LinkButton1 As System.Web.UI.WebControls.LinkButton

'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ShowFolders(CurrentPath)
ShowFiles(CurrentPath)
End Sub

Private Sub ShowFolders(ByVal path)
'Clear the tree
cellFolders.Controls.Clear()

'Debug
Response.Write("Current Path: " & CurrentPath & "<br>")

Dim myImage1 As New ImageButton
'Dim myLink1 As New LinkButton

'Add an uplevel folder
myImage1.ImageUrl = "images/folderup.gif"
cellFolders.Controls.Add(myImage1)
myImage1.ImageAlign = ImageAlign.AbsMiddle
myImage1.ToolTip = "Go up one directory"
myImage1.CausesValidation = True
AddHandler myImage1.Click, AddressOf FolderUpImage_Click

cellFolders.Controls.Add(New LiteralControl("<br>"))

'List all the folders in the current path
Dim s() As String
s = System.IO.Directory.GetDirectories(path)
Dim en As System.Collections.IEnumerator
en = s.GetEnumerator

While en.MoveNext
Dim myImage As New ImageButton
Dim myLink As New LinkButton

myImage.ImageUrl = "images/folder.gif"
myImage.ImageAlign = ImageAlign.AbsMiddle
myImage.ToolTip = GetFileName(CStr(en.Current))
myImage.CausesValidation = True
AddHandler myImage.Click, AddressOf FolderImage_Click

myLink.Text = GetFileName(CStr(en.Current))
myLink.CssClass = "normal"
myLink.CausesValidation = True
AddHandler myLink.Click, AddressOf FolderLink_Click

cellFolders.Controls.Add(myImage)
cellFolders.Controls.Add(New LiteralControl("&nbsp;"))
cellFolders.Controls.Add(myLink)
cellFolders.Controls.Add(New LiteralControl("<br>"))

End While
End Sub

Private Sub ShowFiles(ByVal path)
'Clear the tree
cellFiles.Controls.Clear()

'List all the files in the current path
Dim d() As String
d = System.IO.Directory.GetFiles(path)
Dim en As System.Collections.IEnumerator
en = d.GetEnumerator

While en.MoveNext
Dim myImage As New ImageButton
Dim myLink As New LinkButton

myImage.ImageUrl = "images/html.gif"
myImage.ImageAlign = ImageAlign.AbsMiddle
myLink.Text = GetFileName(CStr(en.Current))
myLink.CssClass = "normal"
cellFiles.Controls.Add(myImage)
cellFiles.Controls.Add(New LiteralControl("&nbsp;"))
cellFiles.Controls.Add(myLink)
cellFiles.Controls.Add(New LiteralControl("<br>"))
End While
End Sub

Private Function GetFileName(ByVal value) As String
Return Microsoft.VisualBasic.Right(value, Len(value) - InStrRev(value, "\", , CompareMethod.Text))
End Function

Private Sub FolderImage_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImageButton1.Click
CurrentPath &= "\" & sender.tooltip
End Sub

Private Sub FolderLink_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LinkButton1.Click
CurrentPath &= "\" & sender.text
End Sub

Private Sub FolderUpImage_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImageButton1.Click
CurrentPath &= Microsoft.VisualBasic.Left(CurrentPath, InStrRev(CurrentPath, "\", , CompareMethod.Text) - 1)
End Sub

End Class
End Namespace

-Todd Davis
http://www.SeaburyDesign.com
joteke
Asp.Net User
Re: Have to click twice to submit - weird problem9/23/2003 6:08:37 PM

0

It is because control lifecycle goes like this:

1. Instantiate
2. Initialize
3. TrackViewState
4. LoadViewState (postback)
5. Load postback data (postback, IPostBackDatahandler.LoadPostdata)
6. Load
7. Load postback data for dynamical controls added on Page_Load
8. Raise Changed Events (postback, IPostBackDatahandler.RaisePostDataChanged)
9. Raise postback event (postback, IPostBackEventHandler.RaisePostBackEvent)
10.PreRender
11. SaveViewState
12. Render
13. Unload
14. Dispose

Pay attention to 6 - 9. Note that postback events are raised after Load event. That means in your case that


Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ShowFolders(CurrentPath)
ShowFiles(CurrentPath)
End Sub


is called before say this:

Private Sub FolderLink_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LinkButton1.Click
CurrentPath &= "\" & sender.text
End Sub


which is postback event handler.

To solve the problem you could:
-Put the code in Load into Not IsPostBack check


Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
ShowFolders(CurrentPath)
ShowFiles(CurrentPath)
End If
End Sub



and on postback event handler call these method as the logic requires after you have updated the CurrentPath property respectively say:

Private Sub FolderLink_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LinkButton1.Click
CurrentPath &= "\" & sender.text
ShowFolders(CurrentPath)
ShowFiles(CurrentPath)
End Sub


(Not sure if OK by the logic but you'll understand the point)
Thanks,

Teemu Keiski
Finland, EU
2 Items, 1 Pages 1 |< << Go >> >|


Free Download:


Web:
Have to click twice to submit - weird problem - ASP.NET Forums Have to click twice to submit - weird problem. Last post 09-23-2003 2:08 PM by joteke .... Re: Have to click twice to submit - weird problem ...
have to click submit or nextpage twice to advance | drupal.org have to click submit or nextpage twice to advance ... I've never been able to reproduce this problem (I don't use IE, nor do I use caching ...
weird problem - Two DB Inserts for each click of "Submit" weird problem - two db inserts for each click of "submit" ... It isn't obvious why it would be submitted twice. ...
JavaServer Pages (JSP) and JSTL - Struts-strange issue-Form ... The problem is, i always have to click the links twice for submitting the form. ... I also don't see the point in having an html form with a link to submit ...
I have a strange problem(possibly spyware related) - Tech Support ... looks like we have found problem right click on blank part of desktop ... press zip to make a copy of any files to submit if we ask for it ...
Weird problem with my NEC-2500 - Club CDFreaks - Knowledge is Power Now, I am trying to burn some dvd movies vob files...twice it locked my pc at 50 % and ... never had this problem before...could have been too many firmware ...
Tech Patterns :: Ajax form, serverside script seems to run twice ... Since form submit also fires the function, the php page gets called twice. You have to put in the explicit protection I made below, trust my stuff, ...
WINAMP.COM | Forums - Strange problem with default WA folder Strange problem with default WA folder. I have been helping in the tech. support ... I tried a full uninstall/reinstall at least twice, ...
WEIRD problem submitting a form on enter key. Please help ... Click to See Complete Forum and Search --> : WEIRD problem submitting ... Most browsers have a built in submit() call when you change a text ...
Weird Click Bug - Tablet PC Forums, Discussion and Support In a program called Pspice I have to double click to change .... Very weird problem in vista, RoyalBean, Gateway, 0, 06-06-2007 10:46 AM ...

Videos:
XML11: An Abstract Windowing Protocol Google TechTalks June 1, 2006 Arno Puder Arno Puder received his masters and Ph.D. in computer science and is currently working as an Assistant Prof...
Lucky Number Seven 777 פלאי השבע 7 Lucky Number Seven !!! פלאי השבע english subtitle הופעת המספר 7 פעמים כה רבות ביהדות ובבריאה, מעוררת השתאות. מהו סודו של ה-7 ? הכיצד יתכן שהיום השבי...






looking for a cheap host for a server i can play with i.e. install longhorn, etc

paging problem in datagrid composite control

building asp.net hyperlink control on-the-fly

get property of top level class

adding design time uitypeeditor for font

design-time support for external stylesheets - possible?

asp.net server control written in vb.net (datagrid)

how to overcome the need to pay for sql2005 in asp.net 2.0 hosting

creating datagrid 1.1

adding button to custom user control

custom control problem,help!!

build asp.net control with c++

big problem with tmaxhost.com

linkbutton in a control force a click on a page

which security templates?

typeconvertor problem

asp:dropdownlist

sometimes i got an error message with my control.

maintaining indent during render

problem getting dynamically created controls from form collection

enclosed tags disappear when using visual studio

server control properties.... by value? or by reference?

derivin from panel or placeholder

collection editor is not displaying object properties

dropdownlists &amp; databases

problem with datagrid checkbox column checkedchange event

creating license for asp .net components

free asp.net hosting???

persisting simple custom class

custom control property problem

   
  Privacy | Contact Us
All Times Are GMT