umki
umki

Reputation: 779

.onClick() function is calling when the page loads?

I want to call the onClick() function only when the related button is clicked. But when i put a debug point in VS2012, I see that this function is calling when the page loads. Is there any method to pretend from this?

 $("#BtnAcik@(OppDetail.ID)").click(function () {                 
    @{
    var RevenuePlan = OppDetail.CRM_REVENUE_PLAN;
    var TotalNewRev = RevenuePlan.Sum(c => c.AMOUNT);
    var SolutionPlan = OppDetail.CRM_SOLUTION_DISTRIBUTION;
    var TotalSol = SolutionPlan.Sum(c => c.AMOUNT);
    if (TotalNewRev == TotalSol){
       <text>
       bootbox.confirm("Eminmisiniz?", function (result) {                   
           if (result === true) {
               window.location = '/opp/ChangeStatusToAcik?OppDetailId=@(OppDetail.ID)';
           } else {

           }

       });
    </text>
    } else{ 
        <text>
        bootbox.alert("Çözüm plani toplami ile gelir plani toplami birbirine esit degil");
        </text>
    }
    } 
});

Upvotes: 0

Views: 234

Answers (1)

Jason P
Jason P

Reputation: 27012

I want to call the onClick() function only when the related button is clicked. But when i put a debug point in VS2012, I see that this function is calling when the page loads.

When you put that breakpoint in there and get stopped on the server, you are breaking during the rendering of the page. Of course that happens on the server, before the page is even passed to the client where javascript can execute.

If you have server-side code that you need to execute after the page has loaded, you'll need to do a postback or an ajax call.

If you want to see when the actual javascript click handler executes, put a breakpoint in the script in the dev tools in your browser.

Upvotes: 2

Related Questions