1

htmnlによって読み取られるサーバー名を持つファイルを取得しようとしています(読み取りを行うためのac#スクリプトを使用)が、名前をhtmlに渡すスクリプトを取得できません。これは次のコードです。

<%@ Page Language="C#" MasterPageFile="~/MasterPage3.master" Title="Services" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <center>
        <script runat="server">
            string[] server = new string[] { };
            void Button1_Click(Object sender, EventArgs e)
            {

                string[] server = System.IO.File.ReadAllLines(@"C:\server.txt");  //here i get the name of the server
         return server[1];
            }
        </script>
        <br />
        <table width="600px" style="border-color: Silver; border-style: solid; border: 1">
            <tr>
                <td style="background-color: LightBlue; text-align: center">
                    <a href="Default.aspx?SERVER=1">1</a>
                </td>
            </tr>
            <tr>
                <td style="background-color: LightBlue; text-align: center">
                    <a href="Default.aspx?SERVER=2">2</a>
                </td>
            </tr>
            <tr>
                <td style="background-color: LightBlue; text-align: center">
                    <a href='Default.aspx?SERVER=' <%#server[1]%>>JD5PKF1</a>
                </td>
                //but i cant get it to be read here
            </tr>
            <input type="button" value="All in one" onclick="location.href='Option2.aspx';">
        </table>
    </center>
</asp:Content>

何か案は?

4

3 に答える 3

1

他の人が報告したエラーに加えて、タグ

<a href='Default.aspx?SERVER='<%#server[1]%>>

読むべきであるため、不正な形式です

<a href='<%# "Default.aspx?SERVER=" + server[1] %>'>

そして、server[] が実際に index=1 の要素を持っているかどうかはチェックしません。

于 2013-02-21T22:38:08.777 に答える
1

Your website doesn't have access to your hard drive. If you want to open a file, you must place it inside the directory that is accessible (for instance place it under same directory as your website)

于 2013-02-21T22:27:03.747 に答える
1

サーバーを 2 回宣言しました。

あなたが使用していない最初のもの。2 番目にテキストを入力すると、範囲外になります。

あなたの意図が何であるかを伝えるのは難しいです。

于 2013-02-21T22:32:50.640 に答える