Fire server code onchange, without submit

Ice

Member
Joined
Jan 25, 2013
Messages
14
Programming Experience
Beginner
Hi is there a way to fire server code without the page submitting.
This code is simplified for what I want to do later, but I need to call my method without a post.

HTML:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Test.aspx.cs" Inherits="Test" %>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript">
        function handler()
        {
            Button1.click();
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:FileUpload ID="FileUpload1" runat="server"  onchange= "handler()" />
    </div>
        <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click"  Style="visibility:hidden" />
    </form>
</body>
</html>

C#:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Test : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        
    }

    public void Button1_Click(Object sender,EventArgs e)
    {
        // When the button is clicked,
        // change the button text, and disable it.
        Response.Write("Bankai!");
        
    }
}
 
Look up EnablePageMethods/WebMethod and UpdatePanel, two ways to achieve that.
 
Back
Top Bottom