Calculating $\langle x | \hat{x} | p \rangle$ in $p$ basis I am trying to calculate $\langle x\ |\ \hat{x}\ |\ p\rangle$. I can work in the $x$-basis like so:
$$\langle x\ |\ \hat{x}\ |\ p\rangle=\int dx'\langle x\ |\ \hat{x}\ |\ x'\rangle\langle x'\ |\ p\rangle=\int dx'x'\langle x\ |\ x'\rangle\langle x'\ |\ p\rangle=x\langle x\ |\ p\rangle=\frac{xe^{ipx/\hbar}}{\sqrt{2\pi\hbar}}.$$
Which steps of this derivation are not correct, if any? 
Second, if I try to do the same thing by using the $p$-basis representation of $\hat{x}$, I get into more trouble:
$$\langle x\ |\ \hat{x}\ |\ p\rangle=\int dp'\langle x\ |\ \hat{x}\ |\ p'\rangle\langle p'\ |\ p\rangle=\int dp'i\hbar\frac{\partial}{\partial p'}\langle x\ |\ p'\rangle\langle p'\ |\ p\rangle$$
$$=\int dp' (-\frac{xe^{ip'x/\hbar}}{\sqrt{2\pi\hbar}})\delta(p-p')=-\frac{xe^{ipx/\hbar}}{\sqrt{2\pi\hbar}}.$$
Hmmm - that doesn't look right - shouldn't the result be the same, no matter which basis or representation I use for $\hat{x}$? Where are the mistakes? Also, I'm not too confident with my own usage of the primes ' all over. Am I using those correctly?
 A: This question (v6) [concerning the overall minus sign in OP's calculation] is essentially a Fourier transformed version of e.g. this Phys.SE post, see Emilio Pisanty's answer and my answer. 
The main point is again that the derivative in the momentum Schrödinger representation 
$$\hat{x}~=~i\hbar\frac{\partial}{\partial p}, \qquad \hat{p}~=~p,$$
acts on the bra (rather than the ket): 
$$\langle p | \hat{x}~=~i\hbar\frac{\partial\langle p |}{\partial p} ,\qquad \langle p | \hat{p}~=~p\langle p |.$$ 
If  one insists to act on kets (as opposed to bras), then the momentum Schrödinger representation comes with the opposite sign: 
$$\hat{x}|p\rangle~=~-i\hbar\frac{\partial|p\rangle}{\partial p} ,\qquad  \hat{p}|p\rangle~=~|p\rangle p.$$ 
The overlap is given as 
$$\langle p | x\rangle~=~\frac{e^{px/i\hbar}}{\sqrt{2\pi\hbar}}. $$
A: You want to use 
$$
\hat x= i\hbar\frac{\partial}{\partial p}
$$
in the momentum basis. This means that 
$$
<p|\hat x|\psi>= i\hbar\frac{\partial}{\partial p} <p|\psi>
$$
Thus, by hermiticity of $\hat x$, we evaluate
$$
<x|\hat x|p> = (<p|\hat x|x>)^* 
$$
$$
=(i\hbar\frac{\partial}{\partial p} <p|x>)^*
$$
$$
=(i\hbar\frac{\partial}{\partial p} e^{-ipx/\hbar})^*
$$
$$
xe^{ipx/\hbar}
$$
which is what you want.
A: I think you have the answer for your second question. For your first question let me clarify:
$$\langle x\ |\ \hat{x}\ |\ p\rangle \overset{(1)}{=}
 \int dx'\langle x\ |\ \hat{x}\ |\ x'\rangle\langle x'\ |\ p\rangle \overset{(2)}{=}
 \int dx'x'\langle x\ |\ x'\rangle\langle x'\ |\ p\rangle \overset{(3)}{=}
  x\langle x\ |\ p\rangle =\frac{xe^{ipx/\hbar}}{\sqrt{2\pi\hbar}}$$
In the first equality you use the fact that $ |x \rangle $, where $x \in \mathbb{R}$ is complete. That is $\int dx'  |\ x'\rangle\langle x'| = \mathbb{1}$ In the second equality you just act on the ket. In the third equality you use the fact that $ |x \rangle $ is orthonormal ie $\langle x\ |\ x'\rangle = \delta(x-x') $, which leaves you with the following:
$$\int \mathrm{d}x'\delta(x-x') \cdot x' \langle x'\ |\ p\rangle = x\langle x\ |\ p\rangle = \frac{xe^{ipx/\hbar}}{\sqrt{2\pi\hbar}}$$
So what you have done is not bogus at all.
A: 
Second, if I try to do the same thing by using the $p$-basis
  representation of $\hat{x}$, I get into more trouble:
$$\langle x\ |\ \hat{x}\ |\ p\rangle=\int dp'\langle x\ |\ \hat{x}\ |\
 p'\rangle\langle p'\ |\ p\rangle=\int
 dp'i\hbar\frac{\partial}{\partial p'}\langle x\ |\ p'\rangle\langle
 p'\ |\ p\rangle$$ $$=\int dp'
 (-\frac{xe^{ip'x/\hbar}}{\sqrt{2\pi\hbar}})\delta(p-p')=-\frac{xe^{ipx/\hbar}}{\sqrt{2\pi\hbar}}.$$

This is wrong. You "moved" the partial derivative to the left through the bra-ket, which is not allowed. You should have "moved" the partial derivative to the right, and then integrated by parts like this:
$$\langle x\ |\ \hat{x}\ |\ p\rangle=\int dp'\langle x\ |\ \hat{x}\ |\ p'\rangle\langle p'\ |\ p\rangle=\int dp'\langle x\ |\ p'\rangle i\hbar\frac{\partial}{\partial p'} \langle p'\ |\ p\rangle$$
$$=\int dp' (\frac{e^{ip'x/\hbar}}{\sqrt{2\pi\hbar}})i\hbar\frac{\partial}{\partial p'}\delta(p-p')
=-\int dp' \delta(p-p')i\hbar\frac{\partial}{\partial p'}(\frac{e^{ip'x/\hbar}}{\sqrt{2\pi\hbar}})
=+\frac{xe^{ipx/\hbar}}{\sqrt{2\pi\hbar}}.$$
