Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Having to click button twice

Posted on 2007-03-21
9
Medium Priority
?
1,435 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

618 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