Javascript function works but C# function doesn't execute

Discussion in 'ASP .Net' started by Jim Hammond, Nov 14, 2003.

  1. Jim Hammond

    Jim Hammond Guest

    The script function in the code below works fine when it is JavaScript, but
    when I try to use C#, the function doesn't get executed.

    <body MS_POSITIONING="GridLayout">

    <form id="Form1" name="Form1" method="post"
    encType="multipart/form-data" runat="server" VIEWASTEXT>
    <asp:button id="Button3" runat="server" Text="TAKE PHOTO"></asp:button>
    </form>

    <script language="C#">
    void TakePicture()
    {
    }
    </script>

    </body>

    I don't know if this is relevant, but I enable the button to call the
    JavaScript function TakePicture() with the following C# code in the web
    form:

    private void Page_Load(object sender, System.EventArgs e)
    {
    if (!IsPostBack)
    Button3.Attributes.Add("onclick", "TakePicture()");
    }
    Jim Hammond, Nov 14, 2003
    #1
    1. Advertising

  2. Jim Hammond

    Polux Guest

    You are trying to execute C# inside the browser. C# can only be executed
    in the server. For client side scripting you must use javascript.

    Most browsers (mozilla, netscape,opera) understand only javascript. (but
    Internet Explorer understand also VBScript)


    Jim Hammond wrote:

    > The script function in the code below works fine when it is JavaScript, but
    > when I try to use C#, the function doesn't get executed.
    >
    > <body MS_POSITIONING="GridLayout">
    >
    > <form id="Form1" name="Form1" method="post"
    > encType="multipart/form-data" runat="server" VIEWASTEXT>
    > <asp:button id="Button3" runat="server" Text="TAKE PHOTO"></asp:button>
    > </form>
    >
    > <script language="C#">
    > void TakePicture()
    > {
    > }
    > </script>
    >
    > </body>
    >
    > I don't know if this is relevant, but I enable the button to call the
    > JavaScript function TakePicture() with the following C# code in the web
    > form:
    >
    > private void Page_Load(object sender, System.EventArgs e)
    > {
    > if (!IsPostBack)
    > Button3.Attributes.Add("onclick", "TakePicture()");
    > }
    >
    >
    Polux, Nov 14, 2003
    #2
    1. Advertising

  3. Jim Hammond

    bruce barker Guest

    the browser does not support C# as a scripting language, but does support
    javascript. C# is only valid with the runat=server attribute, but then of
    course it cannot be called on the client side, but only on a postback


    -- bruce (sqlwork.com)




    "Jim Hammond" <> wrote in message
    news:O#$...
    > The script function in the code below works fine when it is JavaScript,

    but
    > when I try to use C#, the function doesn't get executed.
    >
    > <body MS_POSITIONING="GridLayout">
    >
    > <form id="Form1" name="Form1" method="post"
    > encType="multipart/form-data" runat="server" VIEWASTEXT>
    > <asp:button id="Button3" runat="server" Text="TAKE PHOTO"></asp:button>
    > </form>
    >
    > <script language="C#">
    > void TakePicture()
    > {
    > }
    > </script>
    >
    > </body>
    >
    > I don't know if this is relevant, but I enable the button to call the
    > JavaScript function TakePicture() with the following C# code in the web
    > form:
    >
    > private void Page_Load(object sender, System.EventArgs e)
    > {
    > if (!IsPostBack)
    > Button3.Attributes.Add("onclick", "TakePicture()");
    > }
    >
    >
    bruce barker, Nov 14, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?ZG9ybGluZw==?=
    Replies:
    0
    Views:
    547
    =?Utf-8?B?ZG9ybGluZw==?=
    Jun 24, 2005
  2. F. GEIGER
    Replies:
    3
    Views:
    756
    F. GEIGER
    Aug 6, 2004
  3. Replies:
    0
    Views:
    586
  4. Andrzej
    Replies:
    0
    Views:
    69
    Andrzej
    Oct 6, 2003
  5. atomo
    Replies:
    3
    Views:
    84
    atomo
    Nov 23, 2003
Loading...

Share This Page