Solved

Having to click button twice

Posted on 2007-03-21
9
1,400 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
asp.net bundle 8 47
Set cookies HttpOnly and Secure 4 114
ISS migration from IIS 6 to IIS 8.5 rendering problems 4 52
Entity Framework 7 33
This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

863 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

21 Experts available now in Live!

Get 1:1 Help Now