title: Asp.Net Pass value to Modal TextBox from GridView on button click
body: <p>As stated above, I wanted to know how could I possibly send data from gridview to modal Asp:TextBox</p>
  
  <p><strong>GridView Button</strong></p>
  
  <pre><code>&lt;asp:TemplateField ShowHeader="False"&gt;
  &lt;ItemTemplate&gt;
        &lt;a data-id="&lt;%#Eval("BookFile") %&gt;"  title="Add this item" class="openDialog"&gt;Open Modal&lt;/a&gt;
  &lt;/center&gt;
  &lt;/ItemTemplate&gt;
  &lt;/asp:TemplateField&gt;
  </code></pre>
  
  <p><strong>Script</strong></p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
      $(function () {
          $(".openDialog").click(function () {
              $('#Id').val($(this).data('id'));
              $("#addDialog").modal("show");
          });
      });
  &lt;/script&gt;
  </code></pre>
  
  <p><strong>Modal</strong></p>
  
  <pre><code>   &lt;div class="modal fade" id="addDialog" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true"&gt;
     &lt;div class="modal-dialog modal-dialog-centered" role="document"&gt;
     &lt;div class="modal-content"&gt;
  
         &lt;!-- Modal Head --&gt;
        &lt;div class="modal-header"&gt;
          &lt;h5 class="modal-title" id="myModal1"&gt;Modal title&lt;/h5&gt;
        &lt;/div&gt;
  
        &lt;!-- Modal Body --&gt;
      &lt;div class="modal-body"&gt;
  
              &lt;div class="form-group"&gt;
              &lt;asp:Label runat="server" AssociatedControlID="bookId1" CssClass="col-md-2 control-label"&gt;Username&lt;/asp:Label&gt;
              &lt;div class="col-md-10"&gt;
                  &lt;asp:TextBox runat="server" ID="Id" CssClass="form-control"/&gt;
                  &lt;asp:RequiredFieldValidator runat="server" ControlToValidate="Id"
                      CssClass="text-danger" ErrorMessage="The field is required." /&gt;
              &lt;/div&gt;
          &lt;/div&gt;
  
      &lt;/div&gt;&lt;!--End tag of Modal Body --&gt;
  
        &lt;!-- Modal Footer --&gt;
        &lt;div class="modal-footer"&gt;
          &lt;button type="button" class="btn btn-secondary" data-dismiss="modal"&gt;Close&lt;/button&gt;
          &lt;asp:Button runat="server" OnClick="CreateUser_Click" Text="Add User" CssClass="btn btn-Success" /&gt;
        &lt;/div&gt;
  
  
    &lt;/div&gt;
    &lt;/div&gt;
    &lt;/div&gt;
  </code></pre>
  
  <p>Whenever I use this, no data is populated to the textbox but whenever I use the input box the code works</p>
  
  <pre><code>&lt;input type="text" name="Id" id="Id"&gt; 
  </code></pre>
  
  <p>Thanks in advance!</p>