calling javascript from code-behind

P

Peter Bons

Hi all,

I have an asp.net page with a button that has a javascript onclick method
attached to it to display a modal dialog like this:

If reportHasParameters Then
'add client side onclick() event handler to display the popup dialog for
entering parametervalues
btnChangeParameters.Attributes.Add("onclick",
String.Format("window.showModalDialog
('ParameterPopup.aspx?reportID={0}',
null,'status:no;dialogWidth:640px;dialogHeight:480px;dialogHide:true;help:no;scroll:no');",
Request.QueryString.Item(1)))
Else
btnChangeParameters.Visible = False
End If

this works all right.

Now, the next step is, when te page is loaded the first(!) time, and the
value of the boolean reportHasParameters is TRUE the dialog has to show up
as well.

How can I do that? putting the javascript call in the onload property of the
body tag isn't working because at that time I do not know the value of
reportHasParameters and because then the javascript code is executed every
time a reload takes place.

Somewhere in my code behind, at the Page_Load event I would like to execute
the javascript code like this:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If reportHasParameters Then
'add client side onclick() event handler to display the popup dialog for
entering parametervalues
btnChangeParameters.Attributes.Add("onclick",
String.Format("window.showModalDialog
('ParameterPopup.aspx?reportID={0}',
null,'status:no;dialogWidth:640px;dialogHeight:480px;dialogHide:true;help:no;scroll:no');",
Request.QueryString.Item(1)))

If Not IsPostBack Then
'execute javascript code to show modal dialog
End If
Else
btnChangeParameters.Visible = False
End If

Does someone knows how to accomplish this?

Kind regards and thanx for answering in advance,
Peter
 
B

Bruce Barker

popup blockers (xp-sp2) will prevent this code from working.

-- bruce (sqlwork.com)
 
P

Peter Bons

That's not a serious problem as it will run in an controlled intranet, se we
can set policies to prevent the blocking of te code
 

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

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top