简体   繁体   中英

How to get image map post back value in next page in asp.net?

I have create a web page (page1.aspx) in which I have placed a Image map control. In the image map I have placed a map of India. When I click on a district, it will navigate me to another page (page2.aspx) with information about that district.

I want to be able to transfer the postback value of the area I click onto the page2.aspx, so that I can use it to retrive data on that specific district.

How would I transfer the postback value onto page2?

I am new to asp.net and need help. Thank You in advance.

<asp:ImageMap ID="ImageMap1" runat="server" HotSpotMode="Navigate"    ImageAlign="Middle" ImageUrl="~/Images/Jammu.jpg" OnClick="ImageMap1_Click">
        <asp:PolygonHotSpot AlternateText="Jammu" Coordinates="180, 523,.... 539, 184, 542" HotSpotMode="PostBack" NavigateUrl="~/page2.aspx" PostBackValue="(JK)-Jammu" />
        <asp:PolygonHotSpot Coordinates="492, 526, 506,.... 498, 518" HotSpotMode="PostBack" NavigateUrl="~/page2.aspx" PostBackValue="(JK)-Leh" />
    </asp:ImageMap>
</div>

Try adding a querystring to the NavigateUrl like below:

 <asp:PolygonHotSpot AlternateText="Jammu" Coordinates="180, 523,.... 539, 184, 542" HotSpotMode="PostBack" NavigateUrl="~/page2.aspx?region=JKJammu" PostBackValue="(JK)-Jammu" />
        <asp:PolygonHotSpot Coordinates="492, 526, 506,.... 498, 518" HotSpotMode="PostBack" NavigateUrl="~/page2.aspx?region=JKLeh" 
              PostBackValue="(JK)-Leh" />

See the NavigateUrl...

As MSDN mentioned at https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.imagemap.hotspotmode%28v=vs.110%29.aspx

If you specify HotSpotMode.Navigate for the ImageMap.HotSpotMode property, the page navigates to a URL when the HotSpot is clicked. Use the NavigateUrl property to specify the URL to navigate to.

and

If you specify HotSpotMode.PostBack for the ImageMap.HotSpotMode property, the page generates a postback to the server when the HotSpot is clicked. Use the PostBackValue property to specify the name of the hot spot region. This name will be passed in the ImageMapEventArgs event data when a postback event occurs. When a postback HotSpot is clicked, the Click event is raised. To programmatically control the actions performed when a postback HotSpot is clicked, provide an event handler for the Click event.

so I think you should set the to and then grab the and then manually navigate to the target page using 设置为 ,然后获取 ,然后使用手动导航到目标页面

Response.Redirect("~/page2.aspx?value=" + e.PostBackValue);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM