Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Apr 13, 2012 09:50 AM by sconly
Apr 13, 2012 08:36 AM|LINK
How do i programmatically (in the codebehind) add OnClientClick="aspnetForm.target ='_blank';" to a LinkButton (lbnCtrlTitleChange_ctrl)?
I want the LinkButton to open a new window/tab but only if a textbox has got text in it.
I have the following code but it doesn't seem to be working.
Protected Sub lbnCtrlTitleChange_ctrl_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbnCtrlTitleChange_ctrl.Click
If txtControlID_ctrl.Text <> "" Then
lbnCtrlTitleChange_ctrl.Attributes.Add("OnClientClick", "aspnetForm.target ='_blank';")
Response.Redirect("~/ControlChange.aspx?CtrlID=" & txtControlID_ctrl.Text)
Is the code completely wrong, or just the wrong way to go about it? Please advise.
Apr 13, 2012 08:52 AM|LINK
lbnCtrlTitleChange_ctrl.Attributes.Add("OnClick", "aspnetForm.target ='_blank';")
Apr 13, 2012 08:54 AM|LINK
Rather than doing that on server side, you should check the textbox value at client side
<asp:LinkButton OnClientClick="return fooFunction()" ..
and return false.
BTW, I dont see use of linkbutton, you can go with hyperlink control if you dont want postback.
Apr 13, 2012 09:16 AM|LINK
Thanks for the reply (ramiramilu) but that doesn't open a new tab/window.
Apr 13, 2012 09:20 AM|LINK
Apr 13, 2012 09:50 AM|LINK
I used this little nugget...