2013-06-27 24 views
0

我想創建一個鏈接到一個頁面,該頁面傳遞了FileUpload控件中上傳的文件的路徑。此鏈接需要添加到列表中。當我在鏈接到html的硬編碼時,頁面工作得很好。然而,當我嘗試創建一個動態鏈接我總是收到錯誤:菜單和一個asp:動態添加listitem和menuitem鏈接不工作

The resource cannot be found.

Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.

Requested URL: /WebForm1.apsx

我一直在使用一個asp試用過的BulletedList與超鏈接的顯示模式。下面是html。

<asp:FileUpload ID="FileUpload1" runat="server" Width="600" ToolTip="Choose the Trade Blotter Source File to Upload" /> 
<asp:Button ID="UploadButton" runat="server" Text="Upload File Data"  OnClick="UploadButton_Click" ToolTip="Upload the File Data" /> 
<asp:Menu ID="NavigationMenu" runat="server" CssClass="menu" EnableViewState="false" 
    IncludeStyleBlock="false" Orientation="Horizontal"> 
    <Items> 
     <asp:MenuItem NavigateUrl="~/WebForm1.aspx?param=hubba hubba" Text="without fileupload" /> 
    </Items> 
</asp:Menu> 

<asp:BulletedList ID="BulletedList1" DisplayMode="Hyperlink" runat="server" > 
    <asp:ListItem Value="~/Webform1.aspx?param=New York">New York</asp:ListItem> 

    </asp:BulletedList> 
    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> 

當點擊uploadbutton,該代碼運行,

protected void UploadButton_Click(object sender, EventArgs e) 
    { 
     string s = FileUpload1.FileName; 
     string url = "~/WebForm1.apsx?param=" + s; 

     ListItem li = new ListItem(s, url); 
     BulletedList1.Items.Add(li); 

     MenuItem mu = new MenuItem(s, null, null, url); 
     NavigationMenu.Items.Add(mu); 

    } 

兩者的BulletedList和菜單已經加入到他們的上傳按鈕後鏈接被按下,但兩者的聯繫導致上述錯誤。任何建議,將不勝感激

克里斯

回答

0

你必須在這條線一個錯字:

string url = "~/WebForm1.apsx?param=" + s; 

應該已經

string url = "~/WebForm1.aspx?param=" + s;