LinkButton OnClientClick code help, please.http://forums.asp.net/t/1792483.aspx/1?LinkButton+OnClientClick+code+help+please+Fri, 13 Apr 2012 09:50:07 -040017924834930651http://forums.asp.net/p/1792483/4930651.aspx/1?LinkButton+OnClientClick+code+help+please+LinkButton OnClientClick code help, please. <p>How do i programmatically (in the codebehind) add&nbsp;OnClientClick=&quot;aspnetForm.target ='_blank';&quot; to a LinkButton (lbnCtrlTitleChange_ctrl)?</p> <p>I want the LinkButton to open a new window/tab but only if a textbox has got text in it.</p> <p>I have the following code but it doesn't seem to be working.</p> <pre class="prettyprint">Protected Sub lbnCtrlTitleChange_ctrl_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbnCtrlTitleChange_ctrl.Click If txtControlID_ctrl.Text &lt;&gt; &quot;&quot; Then lbnCtrlTitleChange_ctrl.Attributes.Add(&quot;OnClientClick&quot;, &quot;aspnetForm.target ='_blank';&quot;) Response.Redirect(&quot;~/ControlChange.aspx?CtrlID=&quot; &amp; txtControlID_ctrl.Text) End If End Sub</pre> <p>Is the code completely wrong, or just the wrong way to go about it? &nbsp;Please advise.</p> <p>Thanks</p> 2012-04-13T08:36:34-04:004930669http://forums.asp.net/p/1792483/4930669.aspx/1?Re+LinkButton+OnClientClick+code+help+please+Re: LinkButton OnClientClick code help, please. <p>lbnCtrlTitleChange_ctrl.Attributes.Add(&quot;OnClick&quot;, &quot;aspnetForm.target ='_blank';&quot;)</p> <p>onclientclick is asp.net property...you need to use onclick javascript to define client event...</p> <p>thanks,</p> 2012-04-13T08:52:23-04:004930672http://forums.asp.net/p/1792483/4930672.aspx/1?Re+LinkButton+OnClientClick+code+help+please+Re: LinkButton OnClientClick code help, please. <p>Rather than doing that on server side, you should check the textbox value at client side&nbsp;</p> <p>&lt;asp:LinkButton OnClientClick=&quot;return fooFunction()&quot; ..</p> <p>Javascript fooFunction actually check the textbox value , if that is not null then open new window using &quot;window.open&quot;...</p> <p>and return false.</p> <p>BTW, I dont see use of linkbutton, you can go with hyperlink control if you dont want postback.</p> 2012-04-13T08:54:18-04:004930710http://forums.asp.net/p/1792483/4930710.aspx/1?Re+LinkButton+OnClientClick+code+help+please+Re: LinkButton OnClientClick code help, please. <p>Thanks for the reply (ramiramilu) but that doesn't open a new tab/window.</p> 2012-04-13T09:16:40-04:004930717http://forums.asp.net/p/1792483/4930717.aspx/1?Re+LinkButton+OnClientClick+code+help+please+Re: LinkButton OnClientClick code help, please. <p>Use this&nbsp;<a href="http://www.javascript-coder.com/window-popup/javascript-window-open.phtml">http://www.javascript-coder.com/window-popup/javascript-window-open.phtml</a></p> 2012-04-13T09:20:00-04:004930780http://forums.asp.net/p/1792483/4930780.aspx/1?Re+LinkButton+OnClientClick+code+help+please+Re: LinkButton OnClientClick code help, please. <p>I used this little nugget...</p> <p><a href="http://www.codeproject.com/Tips/317410/Response-Redirect-into-a-new-window">http://www.codeproject.com/Tips/317410/Response-Redirect-into-a-new-window</a></p> 2012-04-13T09:50:07-04:00