Calculating $\langle p|x\rangle$ and $\langle x|\hat{p}|x'\rangle$ - does one result from the other? In showing that $$\langle x|\hat{p}|x'\rangle = -i \hbar \frac{dδ(x-x')}{dx}$$ I've seen many solutions doing something similar to Can I replace eigenvalue of p
operator with position space representation of p
operator?
which uses the fact that $$ p\langle p|x\rangle = -i \hbar \partial_x \langle p|x\rangle $$
in order to get the desired result.
This leads me to think that in calculating $\langle x|\hat{p}|x'\rangle$  we need to know  $\langle p|x\rangle$ (i.e. the differential equation it satisfies).
However, much the same way, when calculating  $\langle p|x\rangle$ I've seen solutions using the fact that $\langle x|\hat{p}|x'\rangle = -i \hbar \partial_x δ(x-x')$ like: 
$$ p\langle p|x\rangle = \langle x|\hat p|p\rangle = \int dy \langle x|\hat{p}|y\rangle \langle y | p \rangle =i\hbar \int dy \frac{dδ(x-y)}{dy}\langle y | p \rangle = -i\hbar \frac{d \langle x | p \rangle}{dx}.$$
My question then is, which comes first? We can't use one in calculating the second and at the same time using the second to calculate the first. Can someone indicate a rigorous way of calculating both without such an interference? 
 A: If you want to calculate either quantity you need to define what the momentum operator does. Without a definition for the momentum operator you can't calculate anything, of course.
Your two identities are just two different ways of defining the action. The most basic way of defining the action of an operator is to define the form of its matrix elements in some known basis. If we have a basis of position eigenstates this would look like $\langle x' | \hat{Q} |x\rangle \equiv Q(x',x)$. That tells us that the operator $\hat{Q}$ acting on a position eigenstate $|x\rangle$ overlaps has an overlap with the position eigenstate $|x'\rangle$ equal to $Q(x',x)$. Your first identity is this kind of statement, so it's one way to define the momentum operator.
Another way of defining an operator is to declare its eigenvalues and eigenvectors. For the momentum operator the eigenvalues are all real numbers $p$, and to define the eigenvectors we give their coefficients in the position basis, $\langle p|x\rangle = \psi_p(x)$. For the momentum operator we define $\psi_p(x) \equiv e^{-ipx/\hbar}$, which is equivalent to your second identity.
These two different ways of defining the action of the momentum operator are equivalent; they can each be used to derive the other. There are other ways of defining the action of the momentum operator as well, and all the good ways are equivalent to these two.
A: I don't think you need to worry about either. 
Note that $i\hbar <x|x'>$ can be written as $<x|[\hat{p}, \hat{x}]|x'>$ and then expand this. You know the left hand side and the right hand side involves the matrix element you want. 
All you need to complete is a property of the Dirac delta function listed (for example) on Wikipedia, which relates $\delta(x)/x$ to the derivative of the delta function itself...
