开发者

While writing the asp.net code it is showing error

开发者 https://www.devze.com 2023-02-06 20:22 出处:网络
i am trying to do a program to upload a document in one page and want to navigate to another page with that document name. i wrote code like this

i am trying to do a program to upload a document in one page and want to navigate to another page with that document name. i wrote code like this

    <%@ Page Title="Home Page" Language="VB" %>
<html>
<head>
    <style type="text/css">
        .style1
        {
            width: 100%;
        }
        .style3
        {
            width: 185px;
        }
        .style4
        {
            width: 129px;
        }
    </style>
    <script language="javascript">
        function doc_save() {
            document.forms[0].submit;
            action = "mynew_page.aspx";
        }
        doc_save();
    </script>
    <script language ="vbscript " runat ="server" >
        Public Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Call save_click()
        End Sub

        Public Sub save_click()
            Response.Write("Saving...")
        End Sub
        </script>
</head>
<body>
<form id="form1" runat="server">
<table class="style1">
    <tr>
        <td class="style4">
            <asp:Button ID="back" runat="server" Text="Back" />
        </td>
        <td class="style3">
            <asp:Button ID="save" runat="server" Text="Save" onClick="doc_save()" />
        </td>
    </tr>
    <tr>
        <td class="style4">
            <asp:Label ID="Label1" runat="server" Text="File Name"></asp:Label>
        </td>
        <td class="style3">
            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        </td>
    </tr>
    <tr>
        <td class="style4">
            <asp:开发者_开发百科Label ID="Label2" runat="server" Text="Description"></asp:Label>
        </td>
        <td class="style3">
           <textarea id="txtarea" name="txtarea" runat ="server" ></textarea></td>
    </tr>
    <tr>
        <td class="style4">
            <asp:Label ID="Label3" runat="server" Text="File Upload"></asp:Label>
        </td>
        <td class="style3">
            <asp:FileUpload ID="FileUpload1" runat="server" Width="330px" />
        </td>
    </tr>
</table>
</form>
</body>
</html>

when i run the program it is showing error like below. of course this code is not yet complete, can u please help to finish this one.

While writing the asp.net code it is showing error


The reason for the error is that you are putting an "onclick" attribute on a server side element (the asp:button). In this context onclick refers to the server side action to be taken when the button is clicked. but because the function you have named doesn't exist in the server code it fails.

Given you have a javascript function I assume this is what you want to call. In this case you should use the onClientClick attribute. http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.button.onclientclick.aspx has information on this and reading around that should give you a better understanding of the subject.


Should the Button call the javascript function? if so, you need to set onClientClick


The error message says you do not have "doc_save()" defined in your aspx code page. you have to convert **<asp:button>** to html **<input>** control and then remove the tag "runat=server" or use OnClientClick on current control as given in other answer.

0

精彩评论

暂无评论...
验证码 换一张
取 消