Solved

Having to click button twice

Posted on 2007-03-21
9
1,390 Views
Last Modified: 2008-03-17
why do I have to click my Accept button twice to get to fire off the Javascript function?  Do I need a check on Postback here?

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        panAgreement.Visible = True

        sb.Append(vbCrLf)
        sb.Append("<script language='javascript' type='text/javascript'>" & vbCrLf)
        sb.Append("<!--" & vbCrLf)
        sb.Append("function closePopUp()" & vbCrLf)
        sb.Append("{" & vbCrLf)
        sb.Append(" window.opener.location.reload();")
        sb.Append(" self.close();")
        sb.Append("}" & vbCrLf)
        sb.Append("//-->" & vbCrLf)
        sb.Append("</script>")
        sb.Append(vbCrLf)
        Page.RegisterStartupScript("closePopUp", sb.ToString)
        btnAccept.Attributes.Add("onclick", "closePopUp()")
    End Sub

    Protected Sub btnAccept_Click(ByVal sender As Object, ByVal e As EventArgs)
        vcUser.UpdateEBookPolicyDate()
        Dim sb As System.Text.StringBuilder = New System.Text.StringBuilder("")

    End Sub
0
Comment
Question by:dba123
  • 6
9 Comments
 
LVL 5

Expert Comment

by:jef06
ID: 18769629
The code can go multiple time in Page_load
you might want to add
If page.IsPostBack = false Then
   btnAccept.Attributes.Add("onclick", "closePopUp()")
Also to not add multiple time the script closeopopup you can check if it is present
if Page.isRegisterStartupScript("closePopUp") = False Then
      Page.RegisterStartupScript("closePopUp", sb.ToString)
0
 
LVL 1

Author Comment

by:dba123
ID: 18772870
hmm, thanks!!!
0
 
LVL 1

Author Comment

by:dba123
ID: 18772947
nope, putting that in didn't help....
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 1

Author Comment

by:dba123
ID: 18772955
also I noticed that Intellisense is not picking this up

isRegisterStartupScript

but is picking up everything else fine such as the egisterStartupScript
0
 
LVL 1

Author Comment

by:dba123
ID: 18773022
I debugged it, but don't see what the problem is.  Your check for the postback is correct.  When I click the button, it definitely is calling Page.RegisterStartupScript("closePopUp", sb.ToString) the first click but nothing happens.
0
 
LVL 1

Author Comment

by:dba123
ID: 18773141
It has something to do with the page lifecycle...probably the register isn't happening the first time through...
0
 
LVL 1

Accepted Solution

by:
dba123 earned 0 total points
ID: 18781658
Ok, figured it out...it was the order of what was happening.

I ended up putting the stringbuilder in the page load but then the call to that function in my button click event and then got rid of the btnAccept.Attributes.Add("onclick", "closePopUp()")
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now