Electric Field due to Linear Charge Distribution 
The above image is taken from the book concepts of Physics by Hc verma.
I am having a bit of trouble understanding that the direction of electric field will always be perpendicular to the curved part of the cylinder

Now consider the electric field made by this particle in the linear charge distribution all the particles below it will also add to the direction. So I think there should be a flux through the top surface.Where am i going wrong here?
This may look like homework question but actually I am struggling with the direction of electric field always being considered in a particular direction. I just want someone to explain to me why is that not considered.
 A: Since the charge distribution the author has assumed here is an infinite rod, therefore every point you select has an "infinite" line of charge above and below it. 
That means the field at every point on the cylinder along the line parallel to the line charge should be the same, simply because assuming an infinite line of charge makes all such points equivalent to one another (with respect to the charge distribution).

Similar arguments go for the direction of the Electric Field. 
If you take a point on the cylinder and calculate the field there, the field should not be able to differentiate between two directions (up and down/left and right) because both of them are equivalent. This means that the field cannot have any component along the up(/down) direction or the left(/right) direction. Hence the field can only be perpendicular to the cylinder. 
If you still don't see why then assume that such a field exists at a particular point in the up direction. Then rotate your view by 180 degrees and then rotate around the line such that your point reaches the same position as before. 
Now, you would notice that the field points downward, in spite of the charge configuration remaining the same as before, which is the contradiction to the assumed field pointing upwards. 
If the infinite charge distributions give you trouble, remember that this problem doesn't represent reality, but they are useful approximations for finding fields where $r<<l$ hence $l$ is "effectively" infinite.
A: Though it is not stated in the problem, Hc verma is assuming that the length of the line of charge is very long compared with the radius and length of the Gaussian surface, and that he is working near the center of the line.  Then, any contribution to the field at a point on the the Gaussian surface which is parallel to the line will be canceled by a contribution which comes from a similar segment of charge which is located down the line in the opposite direction.  If you are looking for the field near the end of the line of charge, you do not have the symmetry needed to make Gauss's Law useful.  Then you would have to find the field components by  summing (integrating) contributions from the various segments of charge.
A: The field at point P can be resolved into parallel (i.e. in the direction of the line of the charges in your diagram) and perpendicular (i.e. perpendicular to the line of charges) components. As for the former, whatever contribution there is from the charges above P will be canceled by the contribution from the charges below P since the line of charge is assumed infinite and therefore there are always equal amounts of charge above and below P. But the contribution to the component of the field in the perpendicular direction from charges above and below P add (and the contributions fall off with distance of charge from P). Thus, there can only be a perpendicular component of the field.
A: Since the line of charge is of infinite length, there will always be a charge on the other side that will produce an electric field whose vertical component will cancel out the vertical component of the field due to first charge. The horizontal components will add up and the direction of net electric field will be radial.
