Opening popup page

KavyaVS
KavyaVS used Ask the Experts™
on
protected void lstListView_SelectedIndexChanging(object sender, ListViewSelectEventArgs e)
        {
           
            lsvListView.SelectedIndex = e.NewSelectedIndex;
            string id = lsvListView.SelectedDataKey.Value.ToString();
            //HttpContext.Current.Response.Redirect("Report_Form.aspx?Reportpath=" +
            //strCNode + "&SnapshotID=" + id);
   
            LinkButton btnlink = (LinkButton)lsvListView.Items[lsvListView.SelectedIndex].FindControl("lnkSelect");
            btnlink.Attributes.Add("onclick", "window.open('Report_Form.aspx?Reportpath=" + strCNode + "SnapshotID=" +
            id + "',null,'height=1000, width=1000,status= no,resizable= yes, scrollbars=yes, toolbar=no,location=no,menubar=no ');");

         }

It is opening the new window. But when retrieved it from query string it is giving the single value reportpath and id together.
Please let me know the syntax error in passing parameters.

To open the window I need to click the button twice.
How to make it work with single click.

Thanks
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Hi!
First parameters should be diveded by & symbol like http://serverl?param1=val1¶m2=val2¶m3=val3
Second try to set use HyperLink, not LinkButton:
//you should also change this in markup
HyperLink link = (HyperLink)lsvListView.Items[lsvListView.SelectedIndex].FindControl("lnkSelect");
HyperLink.NavigateUrl = "javascript:window.open('Report_Form.aspx?Reportpath=" + strCNode + "&SnapshotID=" +
            id + "',null,'height=1000, width=1000,status= no,resizable= yes, scrollbars=yes, toolbar=no,location=no,menubar=no ');"

Author

Commented:

In ListView lnkSelect is LinkButton.
When I used your code I am getting this error.

Unable to cast object of type 'System.Web.UI.WebControls.LinkButton' to type 'System.Web.UI.WebControls.HyperLink'.

Please let me know how to fix it.

Thanks
Can you replace LinkButton with HyperLink in ListView? If not, use following:
 LinkButton btnlink = (LinkButton)lsvListView.Items[lsvListView.SelectedIndex].FindControl("lnkSelect");
 btnlink.OnClientClick = "window.open('Report_Form.aspx?Reportpath=" + strCNode + "&SnapshotID=" +
            id + "',null,'height=1000, width=1000,status= no,resizable= yes, scrollbars=yes, toolbar=no,location=no,menubar=no ');return false";
CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

Author

Commented:
Thanks for your immediate reply.

1.I changed the LinkButton to HyperLink.
But when I click the HyperLink it is not going any where. Nothing is displayed.

2. I used the btnlink.OnClienClick.
Here also I need to click the button twice. Then only popup window showing up.
How to make it work with single click.

Thanks
I'm sorry I missed one thing in your code.
Your button initialization logic is wrong, you should init button's onclient click in selection changed event. This brings your problem with double click - on first click button is getting initialized and on second javascript is executed.

So you should either init all buttons after data bind (e.g. in OnPreRender) or in markup:
protected override void OnPreRender(object sender, ListViewSelectEventArgs e)
{
    foreach(ListViewDataItem item in lsvListView.Item)
   {
         DataKey currentDataKey = lsvListView.DataKeys[item.DataItemIndex];
         LinkButton btnlink = (LinkButton)item.FindControl("lnkSelect");
         btnlink.OnClientClick = "window.open('Report_Form.aspx?Reportpath=" + strCNode + "&SnapshotID=" +
            currentDataKey.Value.ToString()   + "',null,'height=1000, width=1000,status= no,resizable= yes, scrollbars=yes, toolbar=no,location=no,menubar=no ');return false";
   }
}
Sorry, I meant you should NOT init button's onclient click in selection changed event.

Author

Commented:
Thank You So Much. I added your code after listview databind.
Now it is working with single click.

I used selectedItemTemplate in my ListView.The problem is now it is not firing lsvListView_SelectedIndexChanging event,Because of the button OnClienClick event.

The selected row is not highlighting. How to highlight the selected row(I mean the row where the button is clicked)


Please let me know.
Welcome, I'm not sure but try to remove "return false" from OnClientClick:
btnlink.OnClientClick = "window.open('Report_Form.aspx?Reportpath=" + strCNode + "&SnapshotID=" +
            currentDataKey.Value.ToString()   + "',null,'height=1000, width=1000,status= no,resizable= yes, scrollbars=yes, toolbar=no,location=no,menubar=no ');"

Author

Commented:
I tried it after removing "return false" from OnClientClick:

It doesn't make any difference.

Thanks for your response.

Author

Commented:
Thank You Very Much.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial