Click here to Skip to main content
15,884,237 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi, iam using asp.net3.5 with c#,
in my site when i clicks on the button it will open child window of another site but i want to pass the user name and password so that i can directly goes to the link.

below is my code for opening the child window, can any body help me to pass the user name and password directly so that the link is open directly.


C#
string url = "http://10.15.7.38/boxmachine-layout/HQIT159";
       string fullURL = "window.open('" + url + "', '_blank', 'height=500,width=800,status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=no,titlebar=no' );";
       ScriptManager.RegisterStartupScript(this, typeof(string), "OPEN_WINDOW", fullURL, true);
Posted
Comments
developerit 30-Jun-12 8:50am    
this.Page.ClientScript.RegisterStartupScript(GetType(), "dd1", "<script language="'javascript'">window.opener.location.href=http://localhost:9880/testProject/Home.aspx?username='"+UserName+"'&Pass='"+Pass+"'; self.close();</script>");

1 solution

Hi,
You can do it by many ways:
1) Javascript Querystring:
On click of a button in child window just use this:
C#
this.Page.ClientScript.RegisterStartupScript(GetType(), "dd1", "<script language='javascript'>window.opener.location.href=http://localhost:9880/testProject/Home.aspx?username='"+UserName+"'&Pass='"+Pass+"'; self.close();</script>");

But this will not be a good practice.
2)Session:
If you really want to send the username and password then send it through session.
Follow the link for using session variable:
Manage ASP.NET Session Variables using the Facade Design Pattern[^]
http://msdn.microsoft.com/en-us/library/ms178581.aspx[^]

All the best.
--AK
 
Share this answer
 
Comments
developerit 25-Jun-12 8:02am    
hi i have used the above code
but still it is giving error can you correct me

string username = "abc";
string pwd = "123";
this.Page.ClientScript.RegisterStartupScript(GetType(), "dd1", "<script language="'javascript'">window.opener.location.href=http://10.15.4.48/boxmachine-layout/HQIT159?username='" + username + "'&Pass='" + pwd + "'; self.close();</script>");

can you correct me

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