After the Arabs, it was the Ghaznavids who attempted to conquer Kashmir. Mahmud of Ghazni, known for his numerous invasions into India, defeated Raja Jaipal (1002 C.E), the ruler of Waihand (near Peshawar, in modernday Pakistan).Anandpal, the son and successor of Jaipal, also suffered a crushing defeat at the hands of Mahmud in 1009 C.E., and died a few years later. Anandpal's son Trilochanpala, whose power of influence was now confined only to the Salt Range, appealed to Samgramaraja (1003-28 C.E), the king of Kashmir, for help against Mahmud. A large army contingent was sent by Samgramaraja, who joined Trilochanpala's forces, and won a battle against a reconnaissance party of Sultan Mahmud. Seeing this, Mahmud personally advanced for battle and defeated Trilochanpala in 1014 C.E. Provoked by Samgramaraja's conduct, Mahmud decided to invade Kashmir, and punish him. Mahmud advanced towards Kashmir and tried entering the kingdom via the Toshamaidan Pass. His progress was checked by the strong Loharkot Fort, which he besieged for a month. Owing to the heavy snowfall, which cut off Mahmud's communications, he was compelled to retreat. However, the Sultan again set out to invade Kashmir in September-October, 1021 C.E, but was again compelled to retreat due to bad weather conditions.