Click here to Skip to main content
15,889,724 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

On clicking on LinkButton i am opening a new window with particular URL using JavaScript. When i am again clicking on that linkbutton it again opens another window. But i want that again clicking on that linkbutton i want to open that URL in the same window which gets popup on clicking the linkbutton at first time.

My code is given Below
C#
void lnkViewOrderDocuments_Click(object sender, EventArgs e)
{
     StringBuilder sb = new StringBuilder();
     if (null != Request.QueryString[CONST_OrderNo])
     {
         string dmuUrl = OrderHelper.SetDMULinkURLFromConfig(Request.QueryString[CONST_OrderNo].ToString(),
        Request.QueryString[CONST_OrderType].ToString());
        sb.Append(@"<script language='javascript' type='text/javascript'>");
        sb.Append(dmuUrl.Trim());
        sb.Append(@"</script>");
        this.RegisterStartupScript("RegisterSalesTextScript", sb.ToString());
           }
       }
Posted
Updated 16-Jun-11 7:16am
v2

if you are using window.open then specify windowname as below

for example :
C++
window.open("htp://www.google.com","mycustomwindow")
 
Share this answer
 
Comments
Member 4550493 17-Jun-11 5:13am    
Hi,
Thanks for quickly replying to my Question. It's working but what happens when i first click on the linkbutton it opens the window and i minimzed it and again click on that link now that window remains minimized it just refreshesh the content of it.
I want that it must pop up the window after second click which i have minimized

void lnkViewOrderDocuments_Click(object sender, EventArgs e)
{
StringBuilder sb = new StringBuilder();
if (null != Request.QueryString[CONST_OrderNo])
{
string dmuUrl = OrderHelper.SetDMULinkURLFromConfig(Request.QueryString[CONST_OrderNo].ToString(),
Request.QueryString[CONST_OrderType].ToString());
sb.Append(@"<script language="'javascript'" type='text/javascript'>");
sb.Append(dmuUrl.Trim());
sb.Append(@"</script>");
this.RegisterStartupScript("RegisterSalesTextScript", sb.ToString());
}
}
}


sDocumentMergingUtilityURL = string.Format("javascript:window.open('" + sDocumentMergingUtilityURL + "','Window1');return false;");
Try this Javascript function:
function OpenURL()
        {
            var hdnFlag = document.getElementById('<%= hdn.ClientID %>');
            if(hdnFlag.Value > 0)
            {
                window.location = "http://www.google.co.in";
            }
            else
            {
                hdnFlag.Value = 1;                
                window.open("http://www.google.co.in"); 
                self.focus();
            }
        }


Here "hdn" is a hidden field in the page which should keep track if the button is already clicked or not.

Note: Remember that on page refresh this flag will be reset.

Hope this helps!
 
Share this answer
 
in case of window.open use window.showModalDialog
 
Share this answer
 
Comments
Prosan 4-Jun-12 6:12am    
why downvoted it is correct.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900