title: ClientScript.RegisterClientScriptBlock not working with DetailsView_ItemInserting
body: <p>I have a detailsview binded to a ClientEntitydatasource. In DetailsView_ItemInserting i'm trying to check whether user has inserted all the fields and show popup according to that.</p>
  
  <p><strong>PROBLEM</strong></p>
  
  <p>I have found out that if detailsview is <strong>binded</strong> to a datasource following would not execute:</p>
  
  <pre><code> protected void DetailsView1_ItemInserting(object sender, DetailsViewInsertEventArgs e)
      {
  
          if (e.Values["Name"] == null)
          {
              string script = "alert('Please Insert all the mandatory Fields');";
              ClientScript.RegisterClientScriptBlock(this.GetType(), "Alert", script, true); //would not get execute.
          }
      }
  </code></pre>
  
  <p>In order to do that ,I have to explicitly add items to corresponding datasource and  also I have not binded it to ClentEntityDatasource in .aspx as follows:</p>
  
  <pre><code> protected void DetailsView_ItemInserting(object sender, DetailsViewInsertEventArgs e)
      {
  
  
          FileUpload FileUploadControl = DetailsView.FindControl("FileUpload1") as FileUpload;
           if (FileUploadControl.HasFile &amp;&amp; e.Values["Name"] != null)
          {
              string Name = e.Values["Name"].ToString();
              try
              {
                  string FileName = Path.GetFileName(FileUploadControl.FileName);
                  string MapPath = "~/Images/" + FileName;
                  FileUploadControl.SaveAs(Server.MapPath("~/Images/") + FileName);
                  byte[] imgdata = System.IO.File.ReadAllBytes(HttpContext.Current.Server.MapPath(MapPath));
                  SqlConnection myConnection;
                  string myConnectionString = "Initial Catalog=42HNetDb;Data Source=localhost;Integrated Security=SSPI";
                  myConnection = new SqlConnection(myConnectionString);
                  string myInsertQuery = "INSERT INTO Client (Name,Logo) Values(@Name,@Logo )";
                  SqlCommand myCommand = new SqlCommand(myInsertQuery);
                  myCommand.Connection = myConnection;
                  myCommand.Parameters.Add("@Name", SqlDbType.NVarChar);
                  myCommand.Parameters["@Name"].Value = Name;
                  myCommand.Parameters.Add("@Logo", SqlDbType.Image);
                  myCommand.Parameters["@Logo"].Value = imgdata;
                  myConnection.Open();
                  myCommand.ExecuteNonQuery();
                  myCommand.Connection.Close();
              }
              catch (Exception ex)
              {
                  StatusLabel.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message;
              }
          }
          else
          {
             string script = "alert('Please Insert all the mandatory Fields');";
              ClientScript.RegisterClientScriptBlock(this.GetType(), "Alert", script, true); //gets executed properly
          }
  </code></pre>
  
  <p>In short i have found out that if Detailsview is binded to some datasource  <strong>ClientScript.RegisterClientScriptBlock</strong> would not get execute.</p>
  
  <p>I have also tried using   <strong>ScriptManager.RegisterStartupScript</strong> but nothing happens it won't give an error but no popup is shown.
  Am I missing something here??If you need code.aspx just tell me.</p>
  
  <p>Any help would be appreciated.Thanks!!!</p>