Click here to Skip to main content
15,897,315 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
1. I have 4 text boxes and one button in my view page in asp.net
    with c# and MVC.

2. now, on pressing TAB key in first text box, I am calling Stored procedure from a controller and getting Value from one table and displaying that value in second text box..

3. I am doing it using Java script or jquery ...using <http post>..
But Http Post is going to controller only when the page is loaded for the first time....

4. If i Press TAB key for the second time , the page is not posting and Http Post is not firing.

Please Help....Thanks in advance


Here's my View page-'Register_Loan_Account'

HTML
@model Mvc4App10.Models.Loan_Account
@{
    ViewBag.Title = "Register_Loan_Account";
}
@{
    var message = TempData["AlertMessage"] ?? string.Empty;
}

<script src="../../Scripts/jquery-1.7.1.min.js" type="text/javascript"></script>
<script src="../../Scripts/jquery.unobtrusive-ajax.min.js" type="text/javascript"></script>
<script type="text/javascript">

    $(document).ready(function () {
        $('#EMPID').change(function () {
            $.ajaxSetup({
                // Disable caching of AJAX responses
                cache: false;
            });
            $('form').submit();
        });
    });
    </script>

<h2>Register_Loan_Account</h2>

@using (Html.BeginForm())
{ 
  @Html.ValidationSummary(true)

    <fieldset>
       <div class="Editor-label">
         @Html.LabelFor(model=>model.EMPID)
       </div>
       <div class="Editor-field">
        <p> @Html.TextBoxFor(model => model.EMPID, ViewBag.FilterValue as string)</p>
<--clicking Tab key...values from other table is taken using stored procedure from controller and that value is displayed in textbox 'LAmount' -->
         @Html.ValidationMessageFor(model=>model.EMPID)
       </div>

       <div class="Editor-label">
         @Html.LabelFor(model=>model.Rate)
       </div>
       <div class="Editor-field">
         @Html.TextBoxFor(model => model.Rate, ViewBag.FilterValue as string)
         @Html.ValidationMessageFor(model=>model.Rate)
       </div>   

       <div class="Editor-label">
         @Html.LabelFor(model=>model.LAmount)
       </div>
       <div class="Editor-field">
         @*@Html.TextBoxFor(model => model.LAmount, ViewBag.FilterValue as string, new { Value = ViewData["Empid"] })*@
         @Html.TextBoxFor(model => model.LAmount, ViewBag.FilterValue as string)
         @Html.ValidationMessageFor(model => model.LAmount)
       </div>

       <div class="Editor-label">
         @Html.LabelFor(model=>model.Balance)
       </div>
       <div class="Editor-field">
         @Html.TextBoxFor(model => model.Balance, ViewBag.FilterValue as string)
         @Html.ValidationMessageFor(model=>model.Balance)
       </div>

       <div class="Editor-label">
         @Html.LabelFor(model=>model.Remarks)
       </div>
       <div class="Editor-field">
         @Html.TextBoxFor(model => model.Remarks, ViewBag.FilterValue as string)
         @Html.ValidationMessageFor(model=>model.Remarks)
       </div>
      
       <p>
         <input type="submit" value="Register" />
       </p>
    </fieldset>
    
    <div>
       @Html.ActionLink("Back to Index","IndexManualGrid")
    </div>
    
}



---Here's My controller
C#
[HttpPost]
        public ActionResult Register_Loan_Account(Loan_Account Loan1)
        {
             //code....everything is working fine when the page is loaded for the first time....its calling jquery only for the first time...but after then its not coming to controller...plz help
        }
Posted
Updated 13-Sep-15 21:22pm
v5
Comments
swapnil_jadhav 14-Sep-15 2:53am    
Please write your jquery function to call the controller action inside document.ready() function or else please post your code
harshil gandhi 14-Sep-15 3:10am    
ok... i am posting my code which will hepl u
ideafixxxer 14-Sep-15 16:52pm    
I'm not sure what you expect. Should it postback when you press Tab after changing another field? Should it postback when you press tab in EMPID even without changing the value? Or it's not sending postback if after the first postback you change the EMPID value again and press Tab?
harshil gandhi 15-Sep-15 2:12am    
My problem is solved...actually on pressing tab key in EMPID{Textbox],LAmount is changing...and some value from other table is set in LAmount....problem was in my controller and in IF condition.....

Thanks for the reply..@ideafixxxer and Thanks @swapnil_jadhav

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900