Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

ASP.NET Forum


You are currently viewing our ASP.NET Forum as a guest. Please register to participate.
Login



Reply
Which element caused postback?
Old 01-05-2006, 04:34 AM
Minaki's Avatar
Defies a Status

Posts: 1,626
Location: Guildford, UK
Trades: 0
No idea to be honest. It worked perfectly for me when I tried it. Why not store all the images in their own seperate directory?
Alternatively, you could use *.* and check the extention in ItemDataBound...
Code:
If (Right(MyFileInfo.Name, 3) = "gif") Or (Right(MyFileInfo.Name, 3) = "gif") Then
  MyImage.ImageURL = FolderPath & MyFileInfo.Name  ' or whatever
Else
  MyImage.Visible = False
End If
__________________
Minaki Serinde MCP
"Wow, Linux is nearly on-par with Windows ME!"

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
Minaki is offline
Reply With Quote
View Public Profile Visit Minaki's homepage!
 
 
Register now for full access!
Old 01-05-2006, 09:52 AM
Super Talker

Posts: 148
Trades: 0
Yeah, i dont know why dir.getFiles("*.gif,*.jpg") could not work but the checking of extension works fine. Right now, i wish to display the so called staffid (in this case image name without the extension) in the txtSearch control which is created in my webform and not .acsx (user control) file.

I dont know why when i first retrieve the id of the imgSelected control for the first time, it cannot display. I tried saving the value of the id in viewState() but still to no avail.

There were 2 types of methods i have tried, the first coding does not even return a id at all. The second method does but returns the id of image selected previously and not the current id of the image selected. For example, first image selected is id "1", the txtSearch will not display anything. When i click on another image which is id "2" will not be displayed. Instead image id "1" was displayed.

Code:
--First Method--
 'Public Property staffId() As String
    '    Get
    '        Return viewState("staffid")
    '    End Get

    '    Set(ByVal Value As String)
    '        viewState("staffid") = Value
    '    End Set

    'End Property

--Second Method --
    Public ReadOnly Property staffId() As String
        Get
            Return txtURL.Text
        End Get
    End Property
Webform coding
Code:
Protected Image_UC As WebUserControl1
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here
        PlaceHolder1.Controls.Add(Image_UC)
        Image_UC.folderPath = "E:\DIT\Year 3\BRCOM\Assignment\Web Project\BRCOM Assignment\Images"
        txtStaffId.Text = Image_UC.staffId
    End Sub

Those lines highlighted in red is where i assign the image id to the viewState() which is assigned to the textbox.


Code:
 Protected Sub repImages_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles repImages.ItemDataBound
        Dim Item As RepeaterItem = CType(e.Item, RepeaterItem)
        Dim MyImage As New Image
        Dim firstImg As Boolean
        Dim fullFilePath As String
        MyImage = Item.FindControl("imgItem")
        Dim MyFileInfo As System.IO.FileInfo
        'Earlier repImages databind System.IO.FileInfo,
        'therefore need to convert repeater item to System.IO.FileInfo
        MyFileInfo = CType(Item.DataItem, System.IO.FileInfo)
        fullFilePath = strFolderPath & "\" & MyFileInfo.Name

        If (Right(MyFileInfo.Name, 4) = ".gif") Or (Right(MyFileInfo.Name, 4) = ".jpg") Then
            If (imgSelected.ImageUrl = "") Then
                imgSelected.ImageUrl = strFolderPath & "\" & MyFileInfo.Name
                'imgItem that was supposed to have image url of imageSelected
                'will not be displayed.
                MyImage.Visible = False
                'strStaffId = MyFileInfo.Name.Split(".")(0)

                viewState("staffid") = MyFileInfo.Name.Split(".")(0)
                txtURL.Text = viewState("staffid")
            Else
                If (imgSelected.ImageUrl <> strFolderPath & "\" & MyFileInfo.Name) Then
                    MyImage.ImageUrl = strFolderPath & "\" & MyFileInfo.Name
                Else
                    'selected image will not be visible in the asp:repeater
                    MyImage.Visible = False
                    'strStaffId = MyFileInfo.Name.Split(".")(0)
                   viewState("staffid") = MyFileInfo.Name.Split(".")(0)
                    txtURL.Text = viewState("staffid")
                End If
            End If
        Else
            MyImage.Visible = False
        End If

        ' You can set any of the other attributes for the ImageButton control here (ALT text, etc)

    End Sub

Last edited by shaoen01; 01-05-2006 at 09:55 AM..
shaoen01 is offline
Reply With Quote
View Public Profile
 
Old 01-05-2006, 03:54 PM
Minaki's Avatar
Defies a Status

Posts: 1,626
Location: Guildford, UK
Trades: 0
I'm pretty sure that's because you're reading off the property of the control in Page_Load and because of the order events get fired, it will still have its old value at that point. Are you using Visual Studio to do this? If so, you can verify what's happening by putting a breakpoint on the first line of Page_Load and stepping through the code, looking at the values or variables and order of execution.
If not, create a button on the web form, and put
txtStaffId.Text = Image_UC.staffId
into the OnClick event handler of that instead of in Page_Load. Page_Load fires before most other things, so the control won't of had a chance to update itself. You'll most likely want to be responding to a user event (and not the page loading) anyway.
__________________
Minaki Serinde MCP
"Wow, Linux is nearly on-par with Windows ME!"

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
Minaki is offline
Reply With Quote
View Public Profile Visit Minaki's homepage!
 
Old 01-05-2006, 11:41 PM
Super Talker

Posts: 148
Trades: 0
Your right, i am reading off the property in page_load. Pardon me for my ignorance, but i still do not really understand why page_load will not work? I mean page_load is the first event to be fired right?

Anyway, i am using Visual Studio .Net 2003. I tried the breakpoint and found out the sequence of the events fired. I realized that the repImages_ItemDataBound event did not fire, resulting in txtURL being empty.

Besides, using a button and placing
txtStaffId.Text = Image_UC.staffId
into the onclick event, is there any other way to do it? Or no other choice? Because i need the txtSearch to contain the id of the image when loaded immediately.

Thanks

Quote:
Originally Posted by Minaki
I'm pretty sure that's because you're reading off the property of the control in Page_Load and because of the order events get fired, it will still have its old value at that point. Are you using Visual Studio to do this? If so, you can verify what's happening by putting a breakpoint on the first line of Page_Load and stepping through the code, looking at the values or variables and order of execution.
If not, create a button on the web form, and put
txtStaffId.Text = Image_UC.staffId
into the OnClick event handler of that instead of in Page_Load. Page_Load fires before most other things, so the control won't of had a chance to update itself. You'll most likely want to be responding to a user event (and not the page loading) anyway.
shaoen01 is offline
Reply With Quote
View Public Profile
 
Old 01-06-2006, 04:12 AM
Minaki's Avatar
Defies a Status

Posts: 1,626
Location: Guildford, UK
Trades: 0
I think it's because Page_Load fires first that it's not working. In what routine do you call DataBind() for the repeater?
Can you post the whole code for the ASCX control?
__________________
Minaki Serinde MCP
"Wow, Linux is nearly on-par with Windows ME!"

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
Minaki is offline
Reply With Quote
View Public Profile Visit Minaki's homepage!
 
Old 01-06-2006, 04:20 AM
Super Talker

Posts: 148
Trades: 0
Thanks for helping me out ... I really appreciate it.

Code:
Dim strFolderPath As String
    Dim strStaffId As String
    Dim imageSelectedURL As String

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here

        Dim dirInfo As New DirectoryInfo(strFolderPath)
        'Bind all files including the first image that is displayed
        repImages.DataSource = dirInfo.GetFiles("*.*")
        repImages.DataBind()

    End Sub

    'Public Property staffId() As String
    '    Get
    '        Return viewState("staffid")
    '    End Get

    '    Set(ByVal Value As String)
    '        viewState("staffid") = Value
    '    End Set

    'End Property

    Public ReadOnly Property staffId() As String
        Get
            Return txtURL.Text
        End Get
    End Property

    Public Property folderPath() As String
        Get
            Return strFolderPath
        End Get
        Set(ByVal Value As String)
            strFolderPath = Value
        End Set
    End Property

    Protected Sub repImages_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles repImages.ItemDataBound
        Dim Item As RepeaterItem = CType(e.Item, RepeaterItem)
        Dim MyImage As New Image
        Dim firstImg As Boolean
        Dim fullFilePath As String
        MyImage = Item.FindControl("imgItem")
        Dim MyFileInfo As System.IO.FileInfo
        'Earlier repImages databind System.IO.FileInfo,
        'therefore need to convert repeater item to System.IO.FileInfo
        MyFileInfo = CType(Item.DataItem, System.IO.FileInfo)
        fullFilePath = strFolderPath & "\" & MyFileInfo.Name

        If (Right(MyFileInfo.Name, 4) = ".gif") Or (Right(MyFileInfo.Name, 4) = ".jpg") Then
            If (imgSelected.ImageUrl = "") Then
                imgSelected.ImageUrl = strFolderPath & "\" & MyFileInfo.Name
                'imgItem that was supposed to have image url of imageSelected
                'will not be displayed.
                MyImage.Visible = False
                'strStaffId = MyFileInfo.Name.Split(".")(0)
                viewState("staffid") = MyFileInfo.Name.Split(".")(0)
                txtURL.Text = viewState("staffid")
            Else
                If (imgSelected.ImageUrl <> strFolderPath & "\" & MyFileInfo.Name) Then
                    MyImage.ImageUrl = strFolderPath & "\" & MyFileInfo.Name
                Else
                    'selected image will not be visible in the asp:repeater
                    MyImage.Visible = False
                    'strStaffId = MyFileInfo.Name.Split(".")(0)
                    viewState("staffid") = MyFileInfo.Name.Split(".")(0)
                    txtURL.Text = viewState("staffid")
                End If
            End If
        Else
            MyImage.Visible = False
        End If

        ' You can set any of the other attributes for the ImageButton control here (ALT text, etc)

    End Sub

    Public Sub imgItem_Click(ByVal sender As System.Object, ByVal e As ImageClickEventArgs)
        Dim lenOfSplit As Integer
        imgSelected.ImageUrl = CType(sender, ImageButton).ImageUrl

        'strStaffId = imgSelected.ImageUrl.Split(".")(lenOfSplit - 2)
        'txtURL.Text = strStaffId
        Dim dirInfo As New DirectoryInfo(strFolderPath)
        repImages.DataSource = dirInfo.GetFiles("*.*")
        repImages.DataBind()

    End Sub
shaoen01 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Which element caused postback?

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.60568 seconds with 11 queries