asp:button that opens a new webpage?

R

Roy

Ok, I feel silly asking this because it seems like such a simple thing
but I haven't been able to figure it out. Is it possible to create an
asp:button that functions just like an asp:linkbutton? What I'm trying
to do is when a user clicks a button (a pushbutton) it will open a new
page (not response.redirect but an entirely different browser window).

Seems simple, but the answer evades me. :(
 
R

Roy

Hey Steve, thanks for the response, I've checked out the javascript
articles you gave (and many others) and have added javascript
functionality to my webpage. Only problem is, it doesn't work!

I'm assuming it's something simple, but I'll be darned if I know what
it is. Could you eyeball this and let me know where I'm erroring?

Here's my page_load function:
************************
Public Sub Page_Load (sender As Object, e As EventArgs)
Page.RegisterStartupScript("MyScript","<script language=javascript>
function addnewrec() {
window.open(add315.aspx,null,height=200,width=400,status=yes,toolbar=no,menubar=no,location=no);}</script>"
)

If (ISPOSTBACK = FALSE) THEN
BindData()
End If
End Sub
********************************
Now, behold my mighty asp:button! ...which is not so mighty...

<asp:button OnClick="addnewrec()" text="Add New Record"
runat="server"/>

My error is " BC30456: 'addnewrec' is not a member of
'ASP.admin_aspx'."

What gives? No matter how I rework the syntax, the compiler never seems
to recognize addnewrec() as a viable function?

Thanks!
 
S

Steve C. Orr [MVP, MCSD]

You have no quotes around the window.open parameters.
In this case you'll need to use single quotes so they don't conflict with
the double quotes you're already using.
 
S

Steve C. Orr [MVP, MCSD]

Also, add the OnClick attribute to your button tag at run time.
ASP.NET is trying to evaluate this at design time, and it sees that you have
no server side function addnewrec. It doesn't find it because this will be
a client side function, not a server side function.
Use a line of server side code this this to add the attribute at runtime:

MyButton.Attributes.Add("OnClick","addnewrec()")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top