Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Finally have achieved the required functionality. </p> <p>this is how I have done it </p> <p>View (from where the call was made)</p> <pre><code>&lt;input type="submit" value="Create" /&gt; @using (Ajax.BeginForm("Edit", "Home", new AjaxOptions {OnSuccess="DisableControls()", InsertionMode= InsertionMode.Replace,UpdateTargetId="DivToUpdate" })) </code></pre> <p>The Controller </p> <pre><code>[HttpPost] public ActionResult Edit(FormCollection fc) { if (fc.Keys[0].ToString().TrimEnd() == "Display") { TempData["readonly"] = "readonly"; } else TempData["readonly"] = ""; </code></pre> <p>The Called Partial view</p> <pre><code>@model TestApp.Models.CUSTOMER @{ ViewBag.Title = "Edit"; } &lt;script&gt; function s() { var readonly="@TempData["readonly"].ToString()"; if(readonly=="readonly") { $('input[type="text"],select').attr('readonly','readonly'); $("#Save").remove(); } } &lt;/script&gt; &lt;h2 style="padding: 0px; margin-top: 0px;"&gt; Edit&lt;/h2&gt; @using (Html.BeginForm("Save", "Home")) { @Html.ValidationSummary() &lt;fieldset&gt; &lt;legend&gt;CUSTOMER&lt;/legend&gt; &lt;table style="margin: 0px auto;"&gt; &lt;tr&gt; &lt;td&gt; </code></pre> <p>Now on diagnosing the cause for the previous failure attempt I wrote a <code>alert()</code> in the script to see whether the script is executing or not.</p> <pre><code>&lt;script&gt; function s() { var readonly="@TempData["readonly"].ToString()";var s="hi"+ prompt("name",""); alert(s); if(readonly=="readonly") { //To make all text boxes and dropdown readonly $('input[type="text"],select').attr('readonly','readonly'); $("#Save").remove();//To Remove the save button } } &lt;/script&gt; </code></pre> <p>on further looking up with the firebug I could see that the response contains the script </p> <pre><code>&lt;script&gt; function s() { var readonly="readonly";var s="hi"+ prompt("sdfs","kakaji"); alert(s ); if(readonly=="readonly") { $('input[type="text"],select').attr('readonly','readonly'); $("#Save").remove(); } } &lt;/script&gt; &lt;form action="/Grid/Save" method="post"&gt;&lt;div class="validation-summary-valid" data-valmsg-summary="true"&gt; &lt;ul&gt;&lt;li style="display:none"&gt;&lt;/li&gt;&lt;/ul&gt; &lt;/div&gt; &lt;fieldset&gt; &lt;legend&gt;CUSTOMER&lt;/legend&gt; &lt;table style="margin: 0px auto;"&gt; &lt;tr&gt; &lt;td&gt; &lt;div class="editor-label"&gt; </code></pre> <p>But what found that the generated page doesn't include the script for which I found a reason <a href="https://stackoverflow.com/questions/5787280/does-jquery-remove-script-tags-returned-by-ajax-requests">here</a> </p> <p>Hence this solves my problem and gave me a reason behind the fact that WHY I could not see or watch my script tag from the Ajax response.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload