0

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. enter image description here

3 Answers 3

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

0

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.

2 Comments

Removing runat="server" won't help because it's an <asp:button>. You could convert it to a standard html button though (ie <button>) and that would work.
@Chris - Oops, you are right? I failed to notice that. Edited my answer. Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.