Skip to content
Loading
    
  •       class="modal-footer">    
  •         "button" class="btn btn-primary">Save changes    
  •         "button" class="btn btn-secondary" data-dismiss="modal">Close    
  •           
  •         
  •       
  •     
  • then on sucess populate all
     
    1. [WebMethod]    
    2. public static User CheckUsername(string username)    
    3. {    
    4.     using(SqlConnection con=new SqlConnection(cs))    
    5. {    
    6.   SqlCommand cmd= new SqlCommand("select Count(*) from tblUser where Name=@userName");    
    7.   cmd.Parameters.AddWithValue("@userName",username);    
    8.   SqlDataReader rdr= cmd.ExecuteReader();  
    9. User user= new User();  
    10.   while(rdr.Read())  
    11. {  
    12.   
    13. user.Name= rdr["UserName"].ToString();  
    14. // similarly other fields  
    15. }  
    16.    
    17. }    
    18.   return User;  
    19.   }  
    20.   
    21. public class User  
    22. {    
    23.     public int Id{ get; set; }    
    24.     public string Name{ get; set; }    
    25.     public string Address { get; set; }    
    26.     public string MobileNo { get; set; }    
    27. }   
    1. "text/javascript">      
    2.          $("[id$=txtUser]").focusout(function(){      
    3.       
    4.  var username = $("[id$=txtUser]").val();      
    5.             $.ajax({      
    6.                 type: "POST",      
    7.                 url: "PageName.aspx/CheckUsername",      
    8.                 data: '{username: "' + username + '" }',      
    9.                 contentType: "application/json; charset=utf-8",      
    10.                 dataType: "json",      
    11.                 success: function (response) {     
    12.                 if(response) {    
    13.                $("#txtUserName").val(response.Name);  
    14. // similarly other fields  
    15.                  $("#myModal").Modal('show');    
    16.                 }     
    17. }     
    18.             });      
    19.         };      
    20. });      
    21.     
     
    +4
  • Sachin Singh
    +3
    This is very simple
    step 1. Aspx page
     
     
    1. class="modal" tabindex="-1" role="dialog" id="myModal">  
    2.   class="modal-dialog" role="document">  
    3.     class="modal-content">  
    4.       class="modal-header">  
    5.         class="modal-title">Modal title  
    6.         "button" class="close" data-dismiss="modal" aria-label="Close">  
    7.           "true">×  
    8.           
    9.       
      
  •       class="modal-body">  
  •         

    Modal body text goes here.

      
  •         
  •       class="modal-footer">  
  •         "button" class="btn btn-primary">Save changes  
  •         "button" class="btn btn-secondary" data-dismiss="modal">Close  
  •         
  •       
  •     
  •   
  •   
  •   
  •   
  • "text/javascript">    
  •          $("[id$=txtUser]").focusout(function(){    
  •     
  •  var username = $("[id$=txtUser]").val();    
  •             $.ajax({    
  •                 type: "POST",    
  •                 url: "PageName.aspx/CheckUsername",    
  •                 data: '{username: "' + username + '" }',    
  •                 contentType: "application/json; charset=utf-8",    
  •                 dataType: "json",    
  •                 success: function (response) {   
  •                 if(response) {  
  •                  $("#myModal").Modal('show');  
  •                 }   
  • }   
  •             });    
  •         };    
  • });    
  •   
  •   
  •  step 2. Code behind
    1. [WebMethod]  
    2. public static bool CheckUsername(string username)  
    3. {  
    4.     using(SqlConnection con=new SqlConnection(cs))  
    5. {  
    6.   SqlCommand cmd= new SqlCommand("select Count(*) from tblUser where Name=@userName");  
    7.   cmd.Parameters.AddWithValue("@userName",username);  
    8.   int count= Convert.ToInt32(cmd.ExecuteScalar());  
    9.   if(count>=1)  
    10. {  
    11.   return true;  
    12. }  
    13. return false;  
    14.   
    15. }  
    16.   
    17.   }  
    18.    
     
    +3
  • Sachin Singh
    +2
    test this  
    1. if (i > 0)        
    2.             {        
    3.                       
    4.                         
    5.  string url = "restrictedstudents.aspx";        
    6.                     
    7. string Features = "toolbar=no,status=no,menubar=no,location=center,scrollbars=no,resizable=no,height=500,width=657";    
    8. string MyScript = string.Format("window.open('{0}', 'yourWin', '{1}');", url, Features);    
    9.                 ClientScript.RegisterStartupScript(this.GetType(), MyScript , page, true);        
    10.                         
    11.             }      
    +2
  • Bhavesh Vankar
    +1
    i have not used modal.
    i have used aspx page for some records. 
    in my page 1 three textboxes like FName MName Lname when use enter Full Name details in three textboxes  then the name should be match in table if name exists than the popup page should be open with all details of that full name.
    but the query is in form their is three textboxes and the name column in table is only single column like name.
     
    i have used and fetch record like below sql query i want to concat that three textboxes and want to match with table column which is single column.
     
    1. SqlCommand cmd = new SqlCommand("Select Name='"+ txtfname.Text+ " " + txtmname.Text + " " +txtlname.Text + "' From StudentRecord", con);  
     
    +1
  • Bhavesh Vankar
    +1
    i have try like below. when i use response.redirect it working. but below popoup open code not working i want to use it as code behind not by jquery or javascript. if name exist popup should be open as modal.
     see my code and help me to resolve 
    1. string namestring = txtfname.Text + " " + txtmname.Text + " " + txtlname.Text;  
    2.   
    3.             SqlConnection con = new SqlConnection(this.con);  
    4.             con.Open();  
    5.             //SqlCommand cmd = new SqlCommand("Select Name='"+ txtfname.Text+ " " + txtmname.Text + " " +txtlname.Text + "' From RESTICTIED_STUDENTS", con);  
    6.             SqlCommand cmd = new SqlCommand("Select * From RESTICTIED_STUDENTS where Name Like '" + namestring + "'", con);  
    7.             SqlDataAdapter sda = new SqlDataAdapter(cmd);  
    8.             DataSet ds = new DataSet();  
    9.             sda.Fill(ds);  
    10.             int i = ds.Tables[0].Rows.Count;  
    11.             if (i > 0)  
    12.             {  
    13.                 Response.Redirect("restrictedstudents.aspx");  
    14.                   
    15.                 string url = "restrictedstudents.aspx";  
    16.                 string page = "window.open('" + url + "')";  
    17.                 string s = "window.open('" + url + "', 'popup_window', 'width=450,height=500,left=450,top=50,resizable=no');";  
    18.                 ClientScript.RegisterStartupScript(this.GetType(), "script", page, true);  
    19.                   
    20.             }  
     
    +1
  • Bhavesh Vankar
    +1
    myscript is a string variable.?
    1. MyScript = string.Format("'text/javascript'>window.open('{0}', 'yourWin', '{1}');  
    +1
  • Sachin Singh
    +1
    yes a string
    +1
  • Bhavesh Vankar
    +1
    i have implement it as below but no result.
     
    1. string url = "restrictedstudent.aspx";  
    2.                 string page = "window.open('" + url + "')";  
    3.                 string Features = "toolbar=no,status=no,menubar=no,location=center,scrollbars=no,resizable=no,height=500,width=657";  
    4.                 string myScript;  
    5.                 myScript = string.Format("window.open('{0}', 'restrictedstudent.aspx', '{1}');", url, Features);  
    6.    //string s = "window.open('" + url + "', 'popup_window', 'width=450,height=500,left=450,top=50,resizable=no');";  
    7.                 ClientScript.RegisterStartupScript(this.GetType(), myScript,page , true);  
     
    +1
  • Sachin Singh
    +1
    just copy paste my code and run.
    +1
  • Bhavesh Vankar
    +1
    No result sir
    +1
  • Bhavesh Vankar
    +1
    popup page open done by below code....
    thank for your support and guidance.... 
    1. string url = "restrictedstudent.aspx";  
    2. string s = "window.open('" + url + "', 'popup_window', 'width=450,height=500,left=450,top=50,resizable=no');";  
    3. ScriptManager.RegisterStartupScript(this,this.GetType(), "Restricted Persons",s, true);  
    +1