how to use the img tag

2020-03-31 05:24发布

问题:

i am a student working in an simple application and i do not know how to use the img tag and i have tryed one such code but while executing the code the image is not showing plz see the code and help me to saw what is the wrong in the code.

code is:

<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="server">
    &nbsp;
    <table border="0" align="center" cellpadding="0" cellspacing="0" style="width: 100%;
        height: 100%;">
        <tr style="width: 100%; height: 300px;">
            <td valign="middle" align="center">
                <img alt="" src="C:\Documents and Settings\temp.intern1\My Documents\My Pictures\images4.jpg" />&nbsp;
            </td>
        </tr>
        <tr style="height: 65%; vertical-align: top;">
            <td style="width: 90%;" align="center">
                <table cellpadding="0" cellspacing="0" width="100%">
                    <tr>
                        <td style="height: 20px">
                        </td>
                    </tr>
                    <tr>
                        <td align="center" valign="middle" width="100%" style="height: 100%">
                            <div id="Panel1" style="background-color: #87BDEF; height: 300px; width: 600px;">
                                <table cellpadding="0" cellspacing="0" style="height: 400px" width="600px">
                                    <tr>
                                        <td>
                                            &nbsp;
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>
                                            <table cellpadding="0" cellspacing="0" style="height: 200px" width="600px">
                                                <tr>
                                                    <td align="right" style="padding-left: 5px; width: 50%;">
                                                        <asp:Label ID="lblUserName" runat="server" Text="USER NAME &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:"></asp:Label>
                                                    </td>
                                                    <td align="left" style="padding-left: 5px; width: 50%;">
                                                        <br />
                                                        <asp:TextBox ID="txtUserName" runat="server" Width="70%"></asp:TextBox>
                                                        <asp:RequiredFieldValidator ID="rfvUserName" ErrorMessage="Please enter Username"
                                                            ControlToValidate="txtUserName" runat="server" Width="70%" ForeColor="red" Style="margin-left: 0px;" />
                                                        &nbsp;
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>
                                                        <br />
                                                    </td>
                                                    <td>
                                                        <br />
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td align="right" style="width: 50%;">
                                                        <asp:Label ID="lblPassword" runat="server" Text="PASSWORD &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:"></asp:Label>
                                                    </td>
                                                    <td align="left" style="padding-left: 5px; width: 50%;">
                                                        <br />
                                                        <asp:TextBox ID="txtPassword" runat="server" TextMode="Password" Width="70%"></asp:TextBox>
                                                        <asp:RequiredFieldValidator ID="rfvPassword" ErrorMessage="Please enter Password"
                                                            ControlToValidate="txtPassword" runat="server" Width="70%" ForeColor="red" Style="margin-left: 0px" />
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td colspan="2" align="center">
                                                        <span id="lblInValid" style="color: #C00000; font-family: Verdana; font-size: Small;">
                                                        </span>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td colspan="2" align="center">
                                                        <table width="50%">
                                                            <tr>
                                                                <td align="left" style="padding-left: 5px; width: 50%;">
                                                                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                                                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                                                    <asp:Button ID="btnSubmit" runat="server" Text="SUBMIT" OnClick="btnSubmit_Click" />
                                                                    <br />
                                                                    <br />
                                                                    <br />
                                                                </td>
                                                                <td align="left" style="padding-left: 5px; width: 50%;">
                                                                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                                                    <asp:Button ID="btnClear" runat="server" Text="CLEAR" />
                                                                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                                                </td>
                                                            </tr>
                                                        </table>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>
                                                        <br />
                                                    </td>
                                                    <td>
                                                        <br />
                                                    </td>
                                                </tr>
                                            </table>
                                        </td>
                                    </tr>
                                </table>
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td height="180px">
                            <br />
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <br />
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>
</asp:Content>

plz some one help me on this code...,

回答1:

The problem is that you are using an address to an image on your computer, so that will only work when you view the page from that specific computer.

You should copy the image into the web application, for example into a folder named images, then you use that address in the image tag:

<img alt="" src="images/images4.jpg" />


回答2:

Your image should be in the folder accessible to your web server. Try including your image into your solution file (assuming you are using Visual Studio), and use relative path, such as "/images/image4.jpg"

Go to some web site (like www.cnn.com), view source for any page and see how they set path to img tags.

You can also use ASP.Net image tag, check out MSDN for examples and usage.



标签: asp.net