Click here to Skip to main content
15,881,424 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, please someone help me!
i searched alot for it but i couldn't find anything.
i have a button in a page but its click event doesn't fire.
in my page i just have number of textBox and label with this buton and in code behind i have :
C#
protected void btnRegister_Click(object sender, EventArgs e)
   {
       string name = txtName.Text;
       string family = txtFamily.Text;
       int username =Convert.ToInt32( txtUserName.Text);
       int password = Convert.ToInt32(txtRptPassword.Text);
       string email = txtEmail.Text;

       string date = DateTime.Now.ToString();
       bool status = false;
       Membership mem = new Membership(date, status);

       int grpId = Convert.ToInt32(dpdGroup.SelectedItem.Value);
       CourseGroup group = DB.CourseGroups.Where(g=>g.Id==grpId).First();

       bool result = DB.Users.Any(u => u.UserName == username);
       if (group.NumberOfStd < group.Capacity)
       {
           if (result == false)
           {
               Student std = new Student(name, family, username, password, email);
               DB.Users.InsertOnSubmit(std);
               std.AddMembership(mem);
               group.AddMember(mem);
               mem.AssignStudent(std);
               mem.AssignGroup(group);

           }
           else
           {
               Student searchStd = (Student)DB.Users.Where(s => s.UserName == username).First();
               DB.Users.InsertOnSubmit(searchStd);
               searchStd.AddMembership(mem);
               group.AddMember(mem);
               mem.AssignStudent(searchStd);
               mem.AssignGroup(group);

           }
       }
   }
Posted
Comments
Dain Ucak 3-Jun-12 6:30am    
can you share your html side codes

set a break point at:
C#
if (group.NumberOfStd < group.Capacity)

and go on step by step to find the problem!
I guess you get false from your first if statement!
 
Share this answer
 
Comments
parisa heidari 3-Jun-12 7:55am    
Thank you Mr. bahrami it was useful.But what was the broblem why event wasn't fired?

When i set a break point it was fired and i found my problems in code.
taha bahraminezhad Jooneghani 3-Jun-12 8:21am    
some times happens, one day I get an error on commentet code!
we say for joking"get off and get on again!
close vs, restar pc, shut down pc, this work for me several times!
parisa heidari 4-Jun-12 2:46am    
Thank you so much :)
Check your HTML markup for btnRegister_Click event. May be removed.
 
Share this answer
 
Hi,

Check whether the autopostback is true.

Happy Coding
:)
 
Share this answer
 
Comments
parisa heidari 4-Jun-12 2:49am    
It was true, however thanks.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900