Visual Studio .NET - Open New window Through Link Button

Asked By nidhi sood on 16-Dec-11 02:03 PM
I want to open New Window By clicking on the Link button And That Link Button is in Gridview control of asp.net 2.0

Open New Window - Shailendrasinh Parmar replied to nidhi sood on 31-Mar-08 03:17 AM

Write following code to your RowDatabound event of gridview in codebehind ::

LinkButton viewImage; //it is to reassign your linkbutton which is there in your gridview.

//keeping the same name for your understanding.

 ViewImage = (LinkButton)e.Item.FindControl("viewImage");

ViewImage.Attributes.Add("onclick", "return OpenWindow();");

and in OpenWindow function write a javascript

window.open function to open a new window.

for more details of window.open function see the following link ::

http://www.javascript-coder.com/window-popup/javascript-window-open.phtml

Open New window Through Link Button - sri sri replied to nidhi sood on 16-Dec-11 02:03 PM

Hi,
Try this
<asp:TemplateField HeaderText="test">
            <ItemTemplate>
              <asp:LinkButton runat="server" OnClientClick="javascript:window.open('MyPopup.aspx?','','left=250px, top=245px, width=700px, height=450px, scrollbars=no, status=no, resizable=no');return false;">test</asp:LinkButton>
            </ItemTemplate>
          </asp:TemplateField>

Java scrip for the job - ivan fiamengo replied to nidhi sood on 31-Mar-08 02:16 AM

Here is the java script for you,

Since you are using the link button in the gridView control, my guess is that this is the easiest way, just to modify html source

I have given you an example of how to pass some parameters in query string for the next page.


<form id="Form1" method="post" runat="server">
 <a href="http://forums.asp.net/AddPost.aspx?ReplyToPostID=2240521&Quote=False#" mce_href="http://forums.asp.net/AddPost.aspx?ReplyToPostID=2240521&Quote=False#" onclick="openWindow()">Open Popup</a>
</form>

<script type="text/javascript">
<!--
function openWindow()
{
   window.open('Page2.aspx');
}
// -->
</script>

plz help - nidhi sood replied to Shailendrasinh Parmar on 31-Mar-08 02:27 AM
hey, plz tell me what is this view deal and what is the purpose of using imgviewdeal, i haven't used all this
thanx - nidhi sood replied to sri sri on 31-Mar-08 02:33 AM
thanx, its working.
Plz Help for this - nidhi sood replied to ivan fiamengo on 16-Dec-11 02:03 PM
Actually i want to modify my grid view row in the new window, so what to do to open that row with the new window and then to do some modification by clicking on the link button, can u help me for this, i have already created a modification page for that and jst want to open that row with that page and modify
Plzz Help - nidhi sood replied to sri sri on 16-Dec-11 02:03 PM
Actually i want to modify my grid view row in the new window by just clicking on the link button, Can u Help me for this??? plz Help
Help - Shailendrasinh Parmar replied to nidhi sood on 16-Dec-11 02:03 PM

You may be using linkbutton in gridview as template control, right!!. And suppose its ID is 'lnkImage'.

Then have to reassign that linkbutton on your codebehind to use that linkbutton functionlities.. because it is a child control of your grid.


like that as I suggetst you in first answer... see that againg for changes....

dont get confused. use Id whatever you like...


Chill....

Re.Plzz Help - sri sri replied to nidhi sood on 31-Mar-08 03:26 AM
Hi,
While opening the Popup , pass the rowid and values in the querystring.
Read the querystirng values in the popup page

sorry m nt getting - nidhi sood replied to sri sri on 16-Dec-11 02:03 PM

how do i pass them, m not getting all this??? i have id as a primary key how do i open each row in a new window and modify each row


help.. - Santhosh N replied to nidhi sood on 31-Mar-08 04:05 AM

on the click event when you are opening a new window there should be some URL for navigating

for this add the querystring variables as

for ex: this is ut URL

http://mysite/browseDetails.aspx

now add the querystring variable as

http://mysite/browseDetails.aspx?id='10'


hope you got it...

Not Working - nidhi sood replied to Santhosh N on 16-Dec-11 02:04 PM

if we specify one id like u said id='10' then it will open only that row whos id is 10, isnt it?. actually i applied link button to each row in grid view and want to open each row with specific details and my id is a primary key, then would i do this. m doing this, and also applied id but its nt working

<asp:TemplateField>

<ItemTemplate>




</asp:LinkButton>

<asp:LinkButton ID="lbtnEdit" Text="Edit" runat="server" OnClientClick="javascript:window.open('http://localhost:2748/Practice/UpdateDetails.aspx?','','left=600px, top=100px, width=540px, height=600px, scrollbars=no, status=no, resizable=no');return false;" />




</ItemTemplate>


</asp:TemplateField>

help... - Santhosh N replied to nidhi sood on 31-Mar-08 04:29 AM

yeah...dont hardcode the id...

I did specify it as an example...

when u select the row, depending on the row selected you can judge the id right...

send this as the id value in querystring...

ex:

string id = ....//code to get the id of selected row

"http://mysite/browseDetails.aspx?id='" + id + "'";

new window - sri sri replied to Santhosh N on 31-Mar-08 05:13 AM
hi,
try this
<a href="javascript:;" onclick="javascript:window.open('MyPopup.aspx?id=<%#Eval("ID") %>  ','','left=250px, top=245px, width=700px, height=450px, scrollbars=no, status=no, resizable=no');return false;">Test</a>
remove the linkbutton and try using this anchor tag.

<%#Eval("ID") %>  - put your primary key field
Try this.... - Vasanthakumar D replied to nidhi sood on 31-Mar-08 06:09 AM
end of post
Try this.... - Vasanthakumar D replied to nidhi sood on 31-Mar-08 06:13 AM

Hi nidhi,

try the below one...

use this below item template...

<asp:LinkButton ID=”lk” Text=”abc” OnClientClick=’<%# Eval(“ID”,”return OpenWindow( {0} )”)%>’ runat=”server”></asp:LinkButton>

 

Js function ..

function OpenWindow(val)

{

         window.open('popup.aspx?Id=" + val);

         return false;

}

Still Nt Working - nidhi sood replied to sri sri on 31-Mar-08 06:14 AM

<a href="javascript:;" OnClientClick="javascript:window.open('http://localhost:2748/Practice/UpdateDetails.aspx?EmpID=<%#Eval("EmpID")%>','','left=600px, top=100px, width=540px, height=600px, scrollbars=no, status=no, resizable=no');return false;" > Edit </a>

I used this hv a look, what its still nt working.

use this and try... - Santhosh N replied to nidhi sood on 31-Mar-08 06:22 AM
<a href="javascript:;" OnClientClick="javascript:window.open('http://localhost:2748/Practice/UpdateDetails.aspx?EmpID=' + <%#Eval("EmpID")%> + ''','','left=600px, top=100px, width=540px, height=600px, scrollbars=no, status=no, resizable=no');return false;" > Edit </a>
nt done - nidhi sood replied to Vasanthakumar D on 31-Mar-08 06:23 AM

<script type="text/javascript">

function OpenWindow(val)

{

window.open('http://localhost:2748/Practice/UpdateDetails.aspx?EmpID=" + val);

return false;

}

</script>

 

<asp:LinkButton ID="lbtnEdit" Text="Edit" runat="server" OnClientClick='<%# Eval("EmpID","return OpenWindow( {0} )")%>' ></asp:LinkButton>

I used this what nt working

Any Error - sri sri replied to nidhi sood on 31-Mar-08 06:30 AM
Hi,
Do you get any error. is new window is opening or not.?

no - nidhi sood replied to sri sri on 31-Mar-08 06:32 AM
sorry nt opening,
hv a look - nidhi sood replied to sri sri on 16-Dec-11 02:04 PM

<asp:LinkButton ID="lbtnEdit" Text="Edit" runat="server" OnClientClick="javascript:window.open('http://localhost:2748/Practice/UpdateDetails.aspx?EmpID=<% + EmpID + %>,','','left=600px, top=100px, width=540px, height=600px, scrollbars=no, status=no, resizable=no');return false;" />

 

hv a look to this, only in this it will open a new window but nt getting details in my new window


see this - nidhi sood replied to sri sri on 31-Mar-08 06:42 AM

<asp:LinkButton ID="lbtnEdit" Text="Edit" runat="server" OnClientClick="javascript:window.open('http://localhost:2748/Practice/UpdateDetails.aspx?EmpID=<% + EmpID + %>,','','left=600px, top=100px, width=540px, height=600px, scrollbars=no, status=no, resizable=no');return false;" />

this is the only way my new window is opened but nt getting old details in it,  what should i do to get old details in my new window

Replace - sri sri replied to nidhi sood on 16-Dec-11 02:03 PM
hi
try this
<a href="javascript:;" onclick="javascript:window.open('http://localhost:2748/Practice/UpdateDetails.aspx?EmpID=<%#Eval("EmpID") %>,','','left=600px, top=100px, width=540px, height=600px, scrollbars=no, status=no, resizable=no');return false;">Test</a>

why you are using "http://localhost:2748/"
this is not needed. if the main page and sub page is in same directory , just give the page name. other wise give "../Practice/yourpage.aspx"
try this - sri sri replied to nidhi sood on 31-Mar-08 06:45 AM
hi
try this
<a href="javascript:;" onclick="javascript:window.open('http://localhost:2748/Practice/UpdateDetails.aspx?EmpID=<%#Eval("EmpID") %>,','','left=600px, top=100px, width=540px, height=600px, scrollbars=no, status=no, resizable=no');return false;">Test</a>

why you are using "http://localhost:2748/"
this is not needed. if the main page and sub page is in same directory , just give the page name. other wise give "../Practice/yourpage.aspx"
try this - Santhosh N replied to nidhi sood on 31-Mar-08 06:45 AM

in the new window, get the values by querying the database using the empid...

i suppose that is the problem...

see - nidhi sood replied to sri sri on 31-Mar-08 06:48 AM
Again new is opened but nt getting older details in it. I think some coding is needed, isnt it??
try this - sri sri replied to nidhi sood on 31-Mar-08 06:49 AM
after opening the new window read the querystring (EmpId )

Fetch the data for that EmpID and assign those values to the controls.

then save the information


yes.. - Santhosh N replied to nidhi sood on 31-Mar-08 06:50 AM

You are correct..

depending on the empid you need to query the DB to get the values

thanx - nidhi sood replied to sri sri on 31-Mar-08 06:51 AM
ok thanx
quote is missed.... - Vasanthakumar D replied to nidhi sood on 01-Apr-08 12:48 AM

Hi,

check with this...

window.open("http://localhost:2748/Practice/UpdateDetails.aspx?EmpID=" + val);

May be this will help you - Sagar P replied to Vasanthakumar D on 02-Apr-08 12:32 AM

I think your link button is in grid view, so use this and try. Hope it will solve your problem :-)

 <script type="text/javascript">

function OpenWindow(val)

{

window.open('http://localhost:2748/Practice/UpdateDetails.aspx?EmpID=" + val);

return false;

}

</script>

<asp:LinkButton ID="lbtnEdit" Text="Edit" runat="server" OnClientClick=

"javascript:OpenWindow('<%#DataBinder.Eval(Container.DataItem,"EmpId")%>')"

 ></asp:LinkButton>

where EmpId is one of your column

Sujit.

sunny khetarpal replied to nidhi sood on 20-Apr-10 12:56 AM
syntax was wrong...so i modified the little bit and it is working now



<script type="text/javascript">

function OpenWindow(val)

{
alert(val);

window.open("UpdateDetails.aspx?EmpID="+val);

return false;

}

</script>


<asp:LinkButton ID="lnkselect" runat="server" CausesValidation="False"  OnClientClick='<%# Eval("Transid","return OpenWindow({0})")%>'  Text='<%# "INV"+Eval("Transid")%>'></asp:LinkButton>

Shikha Bhardwaj replied to sunny khetarpal on 12-Dec-11 08:03 AM
This syntax works perfectly fine when i have to pass only one argument

<script type="text/javascript">
function OpenWindow(val)
{
alert(val);
window.open("UpdateDetails.aspx?EmpID="+val);
return false;
}
</script> <asp:LinkButton ID="lnkselect" runat="server" CausesValidation="False"  OnClientClick='<%# Eval("Transid","return OpenWindow({0})")%>'  Text='<%# "INV"+Eval("Transid")%>'></asp:LinkButton> But How do I pass 2 values like TransID and Transname in my querystring? Plz help