Question

I am trying to get an asp.net chart and it's legend to allow me to open up another page in another tab passing the values of the piece of the chart I clicked on with it. I have been able to get it to open up another tab when clicking on the chart by doing the following but it does not pass the data.

Chart2.Series[0].LegendUrl = "chartdetails.aspx";
Chart2.Series[0].Url = "chartdetails.aspx";
Chart2.Series[0].LegendMapAreaAttributes="target=\"_blank\"";
Chart2.Series[0].LegendPostBackValue = "#VALY-#VALX";
Chart2.Series[0].MapAreaAttributes="target=\"_blank\"";
Chart2.Series[0].PostBackValue = "#VALY-#VALX";

If I leave out the urls and mapareaattributes I can then get it to go to the onclick where I am able to get the data, put it in a session variable and use Reponse.Redirect to open the new page where it sees the session variable data,however it doesn't open in another tab, it opens in the same tab.

Chart2.Series[0].LegendPostBackValue = "#VALY-#VALX";
Chart2.Series[0].PostBackValue = "#VALY-#VALX";

protected void Chart2_Click(object sender, ImageMapEventArgs e)
{
    HttpContext.Current.Session["VAL"] = e.PostBackValue;
    Response.Redirect("chartdetails.aspx", false);
}

How can I get it to do both? Does Response.Redirect have a way to open a new tab? Some research leads me to believe it does not. Is there a way to get both the server side onclick event to run, so I can set the session variable and the chart.series.url to fire after the server side click runs so the session variable would be set before I open the new tab?

I'm feeling like this may be a case of "I can't have my cake and eat it too."

Was it helpful?

Solution

As it turns out I can have my cake and eat it too. If I set the url, postbackvalues, and legendmapareaattributes in my Page_Load and set up the click for the chart to put the PostBackValue in the session variable when you click on the chart it saves the value in the session variable that is listed in the PostBackValue of the Series of the chart. It then opens in a new tab chartdetails.aspx where I can access the information from the session variable.

Chart2.Series[0].LegendUrl = "chartdetails.aspx";
Chart2.Series[0].LabelUrl = "chartdetails.aspx";
Chart2.Series[0].Url = "chartdetails.aspx";

Chart2.Series[0].LegendPostBackValue = "#VALY-#VALX";
Chart2.Series[0].LabelPostBackValue = "#VALY-#VALX";
Chart2.Series[0].PostBackValue = "#VALY-#VALX";

Chart2.Series[0].LegendMapAreaAttributes = "target=\"_blank\"";
Chart2.Series[0].LabelMapAreaAttributes = "target=\"_blank\"";
Chart2.Series[0].MapAreaAttributes="target=\"_blank\"";

protected void Chart2_Click(object sender, ImageMapEventArgs e)
{
    HttpContext.Current.Session["VAL"] = e.PostBackValue;                  
}

OTHER TIPS

I can't use postback to get the value on the series for some reason. So, I want to share my way inspired by @Adam that is loop over the series points after data binding the chart and set URL.

GET:

Series s=new Series("Test");
/*
*  After Data bind to the series s 
*/
for (int p = 0; p < s.Points.Count; p++)
{
  s.Points[p].Url ="test.aspx?name1=value1&name2=value2";
  s.Points[p].MapAreaAttributes = "target=\"_blank\"";
}

POST:

(I put javascript function in url. So, It will execute the javascript for me to send a form I created in the function to the text.aspx.)

Series s=new Series("Test");
/*
*  After Data bind to the series s 
*/
for (int p = 0; p < s.Points.Count; p++)
{
    s.Points[p].Url ="javascript:(function(){" +
                                "var mapForm = document.createElement('form');mapForm.target = '_blank';" +
                                "mapForm.method = 'POST';mapForm.action = 'test.aspx';" +
                                "var mapInput = document.createElement('input');mapInput.type = 'hidden';" +
                                "mapInput.name = 'partID';mapInput.value = 'put any value you need';" +
                                "mapForm.appendChild(mapInput);document.body.appendChild(mapForm);" +
                                "mapForm.submit();document.body.removeChild(mapForm);})();";
}

Reference:

Javascript pass values using POST

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top