Working code for image upload stops working if used with master page

I have a weird problem; the included code for uploading images into a directory structure works just fine until I include it in a master page. Then suddenly the dropdownlist for directories comes up empty on postbacks. Any suggestions?

ImageUpload.aspx:

<%

@ Page Language="VB" MasterPageFile="~/Web.master" AutoEventWireup="false" CodeFile="ImageUpload.aspx.vb" Inherits="ImageUpload" %>

<

asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

<table>

<tr>

<td>&nbsp;</td>

<td ><asp:FileUpload Width="300" ID="FileUpload1" runat="server" />

<asp:Label ID="FileUploadError_Label" runat="server" Text="A file with this name already exists..." Font-Bold="true" ForeColor="Red" Visible="false"></asp:Label>

</td>

<td><asp:LinkButton ID="LinkButton1" runat="server">Upload image</asp:LinkButton></td>

</tr>

<tr>

<td>Title</td>

<td colspan="2"><asp:TextBox Width="300" ID="Title_TextBox" runat="server"></asp:TextBox></td>

</tr>

<tr>

<td>Notes</td>

<td colspan="2"><asp:TextBox Width="300" Height="200" TextMode="MultiLine" ID="Notes_TextBox" runat="server"></asp:TextBox></td>

</tr>

<tr>

<td>Place in folder</td>

<td colspan="2"><asp:DropDownList Width="300" ID="DropDownList1" runat="server" AutoPostBack="True"></asp:DropDownList></td>

</tr>

<tr>

<td colspan="3">&nbsp;</td>

</tr>

<tr>

<td>New folder</td>

<td><asp:TextBox Width="300" ID="FolderName_TextBox" runat="server"></asp:TextBox></td>

<td><asp:LinkButton ID="LinkButton2" runat="server">Create folder</asp:LinkButton></td>

</tr>

<tr>

<td colspan="3">

<asp:HyperLink ID="HyperLink1" runat="server" Font-Bold="True" ForeColor="Blue" Visible="False">[HyperLink1]</asp:HyperLink>

<asp:Label ID="Label1" runat="server" Font-Bold="True" ForeColor="Red" Text="This folder already exists..." Visible="False"></asp:Label>

</td>

</tr>

</table>

</

asp:Content>

 

Imports

System.IO

Imports

System.Data

Partial

Class ImageUpload

Inherits System.Web.UI.Page

Dim arr As New ArrayList

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

If Not IsPostBack Then

StartDirectory()

End If

End Sub

Protected Sub StartDirectory()

Dim dirPath As String = Server.MapPath("~/Images/")

arr.Add(

"Images\")

BuildDirectory(dirPath)

DropDownList1.DataSource = arr

DropDownList1.DataBind()

End Sub

Protected Sub BuildDirectory(ByVal dirPath As String)

Dim subDirectories As String() = Directory.GetDirectories(dirPath)

For Each directory As String In subDirectories

' Find length of full and partial URL

Dim i As Integer = Server.MapPath("~/").Length

Dim p As Integer = directory.Length - i

Dim parts As String() = directory.Split("\"c)

Dim name As String = parts(parts.Length - 1)

' Don't include folders called with "_thumb" or "_org"

If Not name = "_thumb" And Not name = "_org" Then

' Remove the start of URL to make it relative

arr.Add(directory.Substring(i, p) &

"\")

End If

BuildDirectory(directory)

Next

End Sub

Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged

End Sub

Protected Sub LinkButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LinkButton1.Click

HyperLink1.Visible =

False

FileUploadError_Label.Visible =

False

' Check if a file has been chosen

If FileUpload1.HasFile Then

Dim appPath As String = Server.MapPath("~/") ' Get application directory

Dim folderPath = DropDownList1.SelectedValue ' Add chosen subfolder

Dim fileName As String = FileUpload1.FileName ' Get file name

If File.Exists(appPath & folderPath & fileName) Then

FileUploadError_Label.Visible =

True

HyperLink1.Text = FileUpload1.FileName

HyperLink1.NavigateUrl = folderPath & fileName

Else

'ImageUtils.uploadImage(appPath, folderPath, fileName, Title_TextBox.Text, Notes_TextBox.Text, FileUpload1.FileContent)

HyperLink1.Visible =

True

HyperLink1.Text = FileUpload1.FileName

HyperLink1.NavigateUrl = folderPath & fileName

End If

End If

End Sub

Protected Sub LinkButton2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LinkButton2.Click

Label1.Visible =

False

If FolderName_TextBox.Text <> "" Then

Dim appPath As String = Server.MapPath("~/") ' Get application directory

Dim folderPath = DropDownList1.SelectedValue ' Add chosen subfolder

folderPath = appPath & folderPath & FolderName_TextBox.Text

If Not Directory.Exists(folderPath) Then

Directory.CreateDirectory(folderPath)

StartDirectory()

Else

Label1.Visible =

True

End If

FolderName_TextBox.Text =

""

End If

End Sub

End

Class
0
dennis
7/29/2006 2:20:34 PM
asp.net.navigation-controls 13714 articles. 0 followers. Follow

0 Replies
661 Views

Similar Articles

[PageSpeed] 4

Reply:

Similar Artilces:

user control not working when I use master page.
Hi, I have a user control and it is working properly in my aspx file if I don't use master page. Once I use a master page, the control no longer works. Here is code in my aspx page<%@ Register src="Controls/Spinner.ascx" TagName="Spinner" TagPrefix="wd" %><wd:Spinner ID="Spinner1" runat="server" MinValue=0 MaxValue=10 /> The above works fine without a master page. If I use a master page, I do the following 1. master page <%@ Register src="Controls/Spinner.ascx" TagName="Spinner" TagPrefix="wd&q...

ajax controls stop working after adding master pages
 i had create all web forms  used ajax controls on that like filteredTextBox, calenderextender n all it was working perfectlythen i need to add master page and content pagesi have added master n content page but ajax controls stopped workingthe process i didadd a masterpagethen add all existing pages remove head body form tags from the pageadded a content tag it is working all fine but ajax controls are not working some how i add a new form(driver) in the masterpage project and again added all ajax controls on my content page it starts working only on that form but not on othe...

User Control when dropped on Master Page.........showing error while working with image
hi friends I working in VWD 2005 express edition  The challenge that I m right now facing is I developed a Master Page.<%@ Master Language="C#" AutoEventWireup="true" CodeFile="BalloonShop.master.cs" Inherits="BalloonShop" %> <%@ Register Src="UserControl/Header.ascx" TagName="Header" TagPrefix="uc1" %><!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/xht...

VB.NET control only works when .aspx page uses VB as language
Hello everyone, I created a very extensive .net server control using vb.net. Works like a charm...almost. For some reason, the control requires Language="vb" in the page directive, even if the code-behind file is c#. If the language="C#" in the page directive (with a code behind file ) it gives the error: "The name '__ctrl' does not exist in the class or namespace 'ASP.WebForm1_aspx'" Changing the page directive langauge="vb" solves the problem. If there is no code behind class, but the .aspx page directive has language="C#...

Master Page Default Button bug not working with a TextBox that uses a MaskedEdit Extender control.
Hi,  I have the following code to set the default button of the master page to that of the button on my web page:         Dim myHTMLForm As HtmlForm        Dim myButton As Button        myHTMLForm = CType(Master.FindControl("mainForm"), HtmlForm)        myButton = CType(Me.btnPlaceOrder, Button)        myHTMLForm.DefaultButton = btnPlaceOrder.UniqueID  This works fine for all text box controls bu...

How to use controls of master page in other aspx pages in coding?
 hi all i m working in visual studio 2008 n sql server2005 as a back end n my coding is in VB.actually i m having one problem i have created one master page and in tat i have shopping cart and values qty and amt and i have one Product page which includes this master page .Now in this product page i have different products n within each product i have qty label and text box (i have to call all the products dynamically so i have used data view in all product pages and home page). now i want that whenever anyone add qty in product page qty txt box and click on add to cart button then it sh...

$find does not work in child pages when using Master Pages
Has anyone found  a solution for finding an extender with $find in master pages? Have you tried using the clientID? var hideReceiptPL = document.getElementById('<%=btnHideReceiptPL.ClientID %>'); It may work.....MCPD - Web Developer   actually I should take back all my complaning. this._popup = $find(' <%= mdlPopup.ClientID %>');   I wasnt gathering the ID correctly. my bad...

Using Master Page Controls within the code of the Content page
Does any one know if  you can use controls with in the masterpage in the Code of the content page? An example is: lblDateTime - label control in masterpage I want to use the text Property of this label to input data into some field on the content page. eg. txtDatePosted.text  = lblDateTime.text Stupid example but i hope you get what I mean. Matt Hi Matt,I have had the same problem with an application. I needed to access a control in a page from UserControl used in it. After four days, I found the solution:1) Create a class called "CustomMaster" and inherit System.Web.UI.Mast...

links not working on master page when used by page not in the root folder
hi, sorry for the basic question here. i have a website which i am creating via Visual Web Developer 2008. On the root dir i have my master page with some more pages. I have grouped some pages and placed them in a folder as i may be placing security on them later. The problem is when I go to one of the pages within the folder the images wont appear and the links are broken. i am obviously doing something embarassingly stupid here. path to the master page is : - MyWebsite\master.master path to default.aspx which works fine is MyWebsite\default.aspx path to editnews....

Menu control inside user control located inside Master Page does not work
When I click on any munu items, looks like nothing is getting selected and even MenuItemClick event is not firing up. Any idea?I have defined a menu control with SiteMapDatasource control inside a user control which is located on Master page. Any item selection does not anything...Thanks,Noreen Noreen,The default binding for a Menu control connected to a SiteMapDataSource is to navigate.  It's possible that you're navigating back to your same page?  To get around this you should create a custom databinding and bind the TextField to Title.  Let me know if this doesn...

Page.Form.DefaultFocus doesn't work when using Master Pages??
On "normal" pages that don't use Master Pages, I can use Page.Form.DefaultFocus = control.UniqueID but if the page uses a "Master Page", that doesn't seem to work.  What's the trick to getting this to work when one is using a "Master Page?" Try to Use Page.Form.DefaultFocus = control.ClientID;  Hosam Kamel Remember to click on Mark as answer on the post that helped you HosamKamel: Try to Use Page.Form.DefaultFocus = control.ClientID;   I attempted to do this, but I got an error message: The DefaultButton of 'form1&#...

Using controls from pages, master pages, and user controls
How would I structure my site in this scenario: I'd like to use a dropdownlist all over my site, sometimes in a regular page, sometimes in a master page, and sometimes in a user control.  I wish to bind its events programmatically, so normally I would just put that in the codebehind.  However, I notice a lot of code duplication because I have to declare the control in everywhere, in my base page (which all my pages inherit from), in my base master page (which all my master pages inherit from) and in my base user control (which all my user controls inherit from).How should I be...

treeview to work with javascript disabled,use treeview across pages (treeview present on master page)
helloi am using a treeview in aspx page , the tree view is on master page and the master page is used on other aspx page, the problem is as soon as i go from one aspx page to other through the treeview the nodes are collapsed .i want to retain the state to treeview child nodes expaned .also when i see the pages in firefox with javascript disabled the tree view child nodes does not work.I want to have a tree view structure which can work with java script disabled alsoif any one of you can help, it will be greatthanks Hi For your first problem...Check this post...http://forums.asp.net/t...

treeview to work with javascript disabled,use treeview across pages (treeview present on master page)
helloi am using a treeview in aspx page , the tree view is on master page and the master page is used on other aspx page, the problem is as soon as i go from one aspx page to other through the treeview the nodes are collapsed .i want to retain the state to treeview child nodes expaned .also when i see the pages in firefox with javascript disabled the tree view child nodes does not work.I want to have a tree view structure which can work with java script disabled alsoif any one of you can help, it will be greatthanks Hi, You can do that by saving the expanded nodes in a session variabl...

Web resources about - Working code for image upload stops working if used with master page - asp.net.navigation-controls

Working class - Wikipedia, the free encyclopedia
The working class (also lower class , labouring class , proletariat , or laboring class ) are those employed in lower tier, subordinate jobs. ...

This Is How Facebook Is Working to Improve Experience On Slower Connections
... outlined how it is trying to build out the world’s largest social network, while still keeping emerging markets in mind. Facebook is working ...

Working remotely: Rewarding, but also challenging
... nearly half of developers (44 percent) value the opportunity to work remotely. It’s well known that developers value the perk of remote working, ...

Apple rumored to be working on its own GPU
It's no secret that Apple prefers to own and control as much of the underlying technologies in its products as possible. The number of examples ...

comedian Brian Posehn working on "full metal" LP for Megaforce w/ Scott Ian, Gary Holt, Kim Thayil & ...
Comedian and serious metalhead Brian Posehn is apparently hard at work on a new metal/comedy album, following up his albums Fart and Wiener Jokes ...

Here's how to turn your iPhone into a working scale
It's now possible to turn your new iPhone's screen into a working scale that will measure up to 385 grams (over 13 ounces and slightly less than ...

The answer to working from the beach?
For anyone who's ever toyed with the idea of being a freelancer, CNBC speaks with two successful freelancers who've been there and done that. ...

Crave Ep. 228: Working mini Death Star destroys things quite well
A laser artist shows off his latest creation, threatening mini worlds across the universe.

Kentucky Gov. Matt Bevin says Obamacare not working—70 percent of Kentuckians disagree
A new poll from the Kaiser Family Foundation finds that 72 percent of all Kentuckians want to keep Medicaid the same, opposing Gov. Matt Bevin’s ...

DICE reveals what game it's working on next
Development director Dan Vanderlind has confirmed that DICE is working on an all-new Battlefield game. Though he didn't go into the details ...

Resources last updated: 12/14/2015 6:38:12 PM