2017-12-28 15 views
0

질문이 업데이트되었습니다.ASP.NET JavaScript 함수 호출 코드 숨김

참조 : html로 링크를 클릭은 "일반 추가"때 http://www.startuppirates.org/blog/gritter/

이 제대로 작동 팔로우 그렇게 관련의 .js와 .CSS가 작동 통지를 보여줍니다.

HTML 링크

<a href="#" id="add-regular">Add regular notification</a> 

자바 스크립트

<script type="text/javascript"> 

    $('#add-regular').click(function() { 

     var unique_id = $.gritter.add({ 
      // (string | mandatory) the heading of the notification 
      title: 'This is a regular notice!', 
      // (string | mandatory) the text inside the notification 
      text: 'This will fade out after a certain amount of time.', 
      // (string | optional) the image to display on the left 
      image: '/content/gritter/images/success.png', 
      // (bool | optional) if you want it to fade out on its own or just sit there 
      sticky: false, 
      // (int | optional) the time you want it to be alive for before fading out 
      time: '', 
      class_name: 'gritter-info' 
     }); 
     return false; 
    }); 

</script> 

내가 매개 변수로 함수에 JS 위에 수정 한, 나는 코드 숨김 (ASP에서 알림을 표시하는 호출하려고 해요 .net/web-forms)하지만 작동하지 않습니다!

Codebehind가

Page.ClientScript.RegisterStartupScript(Me.GetType(), "return", "stickyalert('Property Upload', 'property data uploaded successfully', 0, 'success');", True) 

자바 스크립트

<script type="text/javascript"> 
    function stickyalert(title, text, sticky, success) { 
     var unique_id = $.gritter.add({ 
      // (string | mandatory) the heading of the notification 
      title: title, 
      // (string | mandatory) the text inside the notification 
      text: text, 
      // (string | optional) the image to display on the left 
      image: '/content/gritter/images/success.png', 
      // (bool | optional) if you want it to fade out on its own or just sit there 
      sticky: sticky, 
      // (int | optional) the time you want it to be alive for before fading out 
      time: '5000', 
      // (string | optional) the class name you want to apply to that specific message 
      class_name: 'gritter-info' 
     }); 
     return false; 
    } 
</script> 
+0

이 항목은 ASP.NET 페이지입니까? 그렇다면 Web Forms 또는 MVC를 사용하고 있습니까? –

+0

Web Forms, thanks –

+0

웹 응용 프로그램 작동 방식에 대한 이해를 수정해야합니다. 서버 측 코드가 실행될 때 위의 기능이 정의되고 실행될 수있는 사용자 브라우저에서 수십만 킬로미터 떨어져 있습니다. 모든 서버 측 코드는 브라우저 (전체 페이지, 페이지 또는 데이터의 일부)에 응답을 보내고 자바 스크립트가 브라우저에서 실행되기를 기대할 수 있습니다. – Igor

답변

0

가장 좋은 방법은 자신의 기능을 내부에 기능을 넣어하는 것입니다. 그런 다음 click 이벤트에서이 함수를 호출하는 것 외에도 페이지에서 jquery API를 사용하여로드 할 때 함수를 호출하도록 스크립트를 렌더링하십시오.

<script type="text/javascript"> 

    function myFunc() { 
     $.gritter.add({ 
      // (string | mandatory) the heading of the notification 
      title: 'This is a regular notice!', 
      // (string | mandatory) the text inside the notification 
      text: 'This will fade out after a certain amount of time.', 
      // (string | optional) the image to display on the left 
      image: '/content/gritter/images/success.png', 
      // (bool | optional) if you want it to fade out on its own or just sit there 
      sticky: false, 
      // (int | optional) the time you want it to be alive for before fading out 
      time: '', 
      class_name: 'gritter-info' 
     }); 
    } 

    //Call it when the page loads 
    $(document).ready(function() { 
     myFunc(); 
    }); 

    //Call it on the click event 
    $('#add-regular').click(function() { 
     myFunc(); 
     return false; 
    }); 
</script> 
+0

양식 제출 후 코드 숨김에서 호출해야합니다. –

+0

양식 제출 후? 당신은 할 수 없습니다. 질문을 업데이트하십시오. –

+0

@ GeoConcepts, 그럼 당신은 질문에 넣어야합니다. –