title: not able to get data in javascript from c# in asp.net
body: <p>alert message not printing value from myfunction() method
  on page.aspx</p>
  
  <pre><code> &lt;div class="form-group row"&gt;
                      &lt;label for="colFormLabelLg" class="col-sm-2 col-form-label col-form-label-lg"&gt;User Name&lt;/label&gt;
                      &lt;div class="col-sm-10"&gt;
                        &lt;asp:TextBox class="form-control form-control-lg" ID="username" onfocusout="myFunction()" placeholder="UserName" runat="server"&gt;&lt;/asp:TextBox&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
  
  &lt;script type="text/javascript"&gt;
      function myFunction() {
          var ques = &lt;%= myFunction() %&gt;;
          alert(ques + "is your question ");
      }
  &lt;/script&gt;
  </code></pre>
  
  <p>on page.aspx.cs ( In this i have created sql connection Globally)  </p>
  
  <pre><code>protected string myFunction()
          {
              SqlCommand cmd = new SqlCommand();
              cmd.CommandText = "select Pass from Counselor where UserName = @username";
              cmd.Parameters.AddWithValue("@username", username.Text);
              conn.Open();
              try
              {
                  SqlDataReader rdr = cmd.ExecuteReader();
                  if (rdr.Read())
                  {
                      String question = rdr[1].ToString();
                      return question;
                  }
                  else
                  {
                      dangerMessage.Visible = true;
                      dangermsg.InnerText = "User Not found";
                  }
              }
              catch (Exception ex)
              {
                  dangerMessage.Visible = true;
                  dangermsg.InnerText = "error from finding user \n" + ex;
              }
              conn.Close();
              return null;
          }
  </code></pre>
  
  <p>in javascript alert message is not able to read data 
  don't Know why but I think myFunction() in javascript is not calling Properly </p>