calling a function in .cs from .aspx by using java ?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • biotank
    New Member
    • Jun 2010
    • 1

    calling a function in .cs from .aspx by using java ?

    here is the problem I have, I am using JAVA's confirm function on one of the button in my aspx page, and base on the response, I would like to call a function with in the cs file.

    is this possible ?

    below is my aspx code
    Code:
    <asp:Button ID="myButton" runat="server" Text="Click Me"  OnClientClick="ShowTextBoxContent();"/>
    <script type="text/javascript">
     <!--
          function ShowTextBoxContent()
          {  
             if ( confirm('test') = true )
             {
                email();
             }
          }
     --> 
    </script>
  • raulbolanos
    New Member
    • Apr 2009
    • 31

    #2
    What you can do is make this method on the code-behind like an AjaxPro method.

    In order to do that, you have to download the library file by Michael Schwarz (http://www.ajaxpro.info/) and add it to the references.

    After that, add to the Web.config httpHandlers tag, the next entry:

    Code:
    <add verb="POST,GET" path="ajaxpro/*.ashx" type="AjaxPro.AjaxHandlerFactory, AjaxPro.2"/>
    Then, inside the Page_Load add the next line:

    Code:
    AjaxPro.Utility.RegisterTypeForAjax(typeof(_Default));
    Your confirm method on the code-behind, you have to append before the function declaration, the followin attibute:
    Code:
    [AjaxPro.AjaxMethod]
    function confirm(string target) 
    {
      //what ever the code is
    }
    Once you have donne this procedure, you call the code-behind function from Javascript like this
    Code:
    {ClassName}.confirm('test');
    
    for example
    
    _Default.confirm('test');
    
    Afterwards, if you get a compilation error, it maybe because you have to comment the namespace on the code-behind, like this:
    
    //namespace newProyect 
    //{
    
      class _Default { .. }
    //}
    and the same way on the aspx.designer.c s

    At the end you must also remove the namespace name from the code-behind reference at the aspx file
    Code:
    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="{removeNameSpaceName}._Default" %>
    and it must be like this

    Code:
    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="_Default" %>
    I hope this works for you.
    Last edited by Frinavale; Sep 3 '10, 03:29 PM. Reason: Please post code in [code] ...[/code] tags. Added code tags.

    Comment

    Working...