[.net] ASP.NET control confusion

Started by
2 comments, last by Alpha_ProgDes 15 years, 5 months ago
This should be copy and pastable, as is. Anyway I'm using this AJAX Upload Control (link) and labels to determine where to upload the files to. Now the Labels don't seem to act the way I expect them to. The function findParentTab works as expected to upload the files if I put it in the managePost function as shown. But on the web page, the labels are not updated. They show their default text: Label. If I move the function outside of managePost, then the labels update correctly but the files are uploaded to folder: Label/Label. So I'm wondering if this is a TabPanel problem or Page Load problem.
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" Debug="true" %>

<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="cc1" %>
<%@ Register assembly="FUA" namespace="Subgurim.Controles" tagprefix="cc2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
    <div>
    
        <cc1:TabContainer ID="TabContainer1" runat="server" ActiveTabIndex="2">
            <cc1:TabPanel runat="server" HeaderText="TabPanel1" ID="TabPanel1">
            </cc1:TabPanel>
            <cc1:TabPanel runat="server" HeaderText="TabPanel2" ID="TabPanel2">
            <ContentTemplate>
                <cc1:TabContainer ID="TabContainer2" runat="server" ActiveTabIndex="1">
                    <cc1:TabPanel ID="TabPanel4" HeaderText="TabPanel4" runat="server">
                    <ContentTemplate>
                        <cc2:FileUploaderAJAX ID="FileUploaderAJAX1" MaxFiles="5" runat="server" />
                        <asp:Button ID="ButtonFinder" runat="server" Text="Button" />
                    </ContentTemplate>
                    </cc1:TabPanel>
                    <cc1:TabPanel ID="TabPanel5" HeaderText="TabPanel5" runat="server"></cc1:TabPanel>
                    <cc1:TabPanel ID="TabPanel6" HeaderText="TabPanel6" runat="server"></cc1:TabPanel>
                </cc1:TabContainer>
            </ContentTemplate>
            </cc1:TabPanel>
            <cc1:TabPanel ID="TabPanel3" runat="server" HeaderText="TabPanel3">
            </cc1:TabPanel>
        </cc1:TabContainer>
          
    </div>
    
    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
    </form>
</body>
</html>
Imports Subgurim.Controles

Partial Class _Default
    Inherits System.Web.UI.Page

    Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load


    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If (FileUploaderAJAX1.IsPosting) Then
            managePost()
        End If
    End Sub

    Protected Sub managePost()

        findParentTab()

        Dim pf As HttpPostedFileAJAX = FileUploaderAJAX1.PostedFile
        Dim huh As String = Label1.Text
        Dim duh As String = Label2.Text
        If (pf.Type = HttpPostedFileAJAX.fileType.text And pf.ContentLength <= 5 * 1024) Then

            FileUploaderAJAX1.SaveAs("~/" & Label1.Text & "/" & Label2.Text, pf.FileName)
        End If

    End Sub

    Protected Sub findParentTab()
        Dim level2Control As Control = ButtonFinder.Parent
        While Not (TypeOf level2Control Is AjaxControlToolkit.TabPanel)
            level2Control = level2Control.Parent
        End While
        Label2.Text = level2Control.ID.ToString()

        Dim level1Control As Control = level2Control.Parent
        While Not (TypeOf level1Control Is AjaxControlToolkit.TabPanel)
            level1Control = level1Control.Parent
        End While
        Label1.Text = level1Control.ID.ToString()

    End Sub

    Protected Sub ButtonFinder_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ButtonFinder.Click
        findParentTab()
    End Sub
End Class

Beginner in Game Development?  Read here. And read here.

 

Advertisement
Any takers?

Beginner in Game Development?  Read here. And read here.

 

Im not clear what you want?
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load        findParentTab()    End Sub    Protected Sub Page_LoadComplete(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load        If (FileUploaderAJAX1.IsPosting) Then            managePost()        End If    End Sub    Protected Sub managePost()        Dim pf As HttpPostedFileAJAX = FileUploaderAJAX1.PostedFile        Dim huh As String = Label1.Text        Dim duh As String = Label2.Text        ' If (pf.Type = HttpPostedFileAJAX.fileType.text And pf.ContentLength <= 500 * 1024) Then        FileUploaderAJAX1.SaveAs("~/" & Label1.Text & "/" & Label2.Text, pf.FileName)        '  End If    End Sub
Your problem though sounds like a common trip up point of the .NET Post Back Cycle that i too have stumbled on alot.
With this page and this page and a bit from this page, I was able to finally get it behave correctly. And thank you Daerax!

Imports Subgurim.ControlesPartial Class _Default    Inherits System.Web.UI.Page       Protected Sub Page_InitComplete(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.InitComplete        findParentTabs()    End Sub    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load        If (FileUploaderAJAX1.IsPosting) Then            managePost()        End If    End Sub    Protected Sub managePost()        Dim pf As HttpPostedFileAJAX = FileUploaderAJAX1.PostedFile        Dim huh As String = Label1.Text        Dim duh As String = Label2.Text        If (pf.Type = HttpPostedFileAJAX.fileType.text And pf.ContentLength <= 5 * 1024) Then            FileUploaderAJAX1.SaveAs("~/" & huh & "/" & duh, pf.FileName)        End If    End Sub    Protected Sub findParentTabs()        Dim level2Control As Control = ButtonFinder.Parent        While Not (TypeOf level2Control Is AjaxControlToolkit.TabPanel)            level2Control = level2Control.Parent        End While        Label2.Text = level2Control.ID.ToString()        Dim level1Control As Control = level2Control.Parent        While Not (TypeOf level1Control Is AjaxControlToolkit.TabPanel)            level1Control = level1Control.Parent        End While        Label1.Text = level1Control.ID.ToString()    End Sub    Protected Sub ButtonFinder_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ButtonFinder.Click    End SubEnd Class

Beginner in Game Development?  Read here. And read here.

 

This topic is closed to new replies.

Advertisement