Jump to content

Checkbox


soona

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 = "";	}}

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...