How to create button to open another apx.net web page in VB.Net 2003

163 views Asked by At

Previously I managed to create a code that can open a new aspx page with a click of a button in VB.Net 2010.

    Protected Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button2.Click

    Dim a = "UpdateForm.aspx"
    Dim openWin As String = "window.open('" & a & "');"
    ClientScript.RegisterStartupScript(Me.GetType(), "pop", openWin, True)

    End Sub

Now I want to use the same code on VB.Net 2003 but for some reason I got hit with the error

Name 'ClientScript' is not declared.

Is this because of the difference between 2003 and 2010? Are they any workarounds for this?

1

There are 1 answers

3
Tetsuya Yamamoto On BEST ANSWER

You should try to add Page instance before using ClientScript:

Page.ClientScript.RegisterStartupScript(Me.GetType(), "pop", openWin, True)

Note that ClientScript property is a property defined inside Page class, hence you should include Page instance to access it.

Note:

For ASP.NET 1.1 (and VB.NET 2003) just use Page.RegisterStartupScript as follows:

Dim openWin As String = "<script>window.open('" & a & "');</script>"
Page.RegisterStartupScript("pop", openWin)

Also you need to add opening and closing script tags because deprecated Page.RegisterStartupScript method doesn't have addScriptTags parameter which automatically add script tag if it set as True.

Related issues:

Name 'ClientScript' is not declared

Clientscript.RegisterStartupScript not working