Jump to content

Checkbox


soona
 Share

Recommended Posts

Hi,I am using asp.net with c#.i want to see the url link open in new window.when the checkbox will check. otherwise the link url open in same window without check the checkbox.how can i write code for this? i can see only link opened in new window for this code "chkNewWindow.Checked =true" on Page_Load event.In storeprocdure i have created field for 'chkwindows' with 'bit' datatype.Thanks

Link to comment
Share on other sites

I can't give you code, but I think you will need to load a new page first, and then change its URL.

Link to comment
Share on other sites

There are two ways to open up a new window in a browser: setting the target of a link or using window.open in javascript.If you don't care about changing the behavior when a user clicks on the checkbox and only want this to happen when the page first loads, you can set the target value in the code-behind.ASPX:

<input type="checkbox" id="MyCheckbox" runat="server" /><a href="somepage.aspx" id="MyLink" runat="server">Click Me</a>

C#

if(MyCheckbox.Checked){	MyLink.Target = "_blank";}else{	MyLink.Target = string.Empty;}

On the other hand, if you want this action to change as soon as the user toggles the checkbox, you'll have to do it on the client side:HTML

<input type="checkbox" id="MyCheckbox" onclick="toggle(this, 'MyLink');" /><a href="somepage.aspx" id="MyLink">Click Me</a>

Javascript

function toggle(cb, linkID){	if(cb.checked)	{		document.getElementById(linkID).target = "_blank";	}	else	{		document.getElementById(linkID).target = "";	}}

Edited by jesh
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...