Hi I am trying this since last four days but not getting it to work. I have a tree view control in my page with which I am creating html button with each tree node in code behind.
Like this:
foreach (DataRow row in ds.Tables[0].Rows)
{
{
TreeNode childTreeNode = new TreeNode();
string date_created = row["date"].ToString();
string date = DateTime.Parse(date, CultureInfo.InvariantCulture).ToString("MM/dd/yyyy");
StringBuilder text = new StringBuilder();
text.Append(row["col_name"].ToString() + " " + row["col_name"].ToString() + "." + row["col_name"].ToString() + "." + row["col_name"].ToString() + " <span style='color: black;fontstyle:italic;'>" + " (Created Date-" + date + ") " + "</span>");
text.Append(@"<button onclick=""javascript:clickedMe""><img src=""/Images/getInfo.png"" width=""30"" height=""15"" ></button>");
childTreeNode.Text = text.ToString();
So this part is working just fine. Right now what I am doing is that in my aspx page I have a javascript method as follows:
<script type ="text/javascript" language="javascript">
function clickedMe() {
<%
if(IsPostBack)
{
getResult();
}
%>
}
<;/script>
and in my code behind I have this getResult() method as follows:
public void btnGetData()
{
try
{
{
Session["name"] = TreeView1.SelectedNode.Text;
if (IsPostBack)
{
Session["name"] = TreeView1.SelectedNode.Text;
TreeView1.SelectedNode.Selected = false;
ScriptManager.RegisterStartupScript(this, typeof(string), "OPEN_WINDOW", "var Mleft = (screen.width/2)-(760/2);var Mtop = (screen.height/2)-(700/2);window.open( 'GetResult.aspx', null, 'height=400,width=800,status=yes,toolbar=no,minimizable=yes,maximizable=no, resizable= yes,scrollbars=yes,menubar=no,location=no,top=\'+Mtop+\', left=\'+Mleft+\'' );", true);
}
}
}
catch (Exception ex)
{
Exception E = ex;
}
}
I also have treeview node change event.
public void Select_Change(Object sender, EventArgs e)
So Clicking on button and node should open different windows.
The problem: When I click to button and after clicking on button if I click on the node associated with the same button I clicked, it opens the same window(i.e. opened by button), it should open different window. But if I click on another node it works fine and after clicking on another node if I click on that node again it will work fine.
I am really confused with this. I have tried almost all ways to solve this problem from the internet.
Is there is a way that I can attach my button to Click event Handler. I have tried it but it always gives me error while running that method is undefined.
Please help me.