Solved

New Window from ASP.net button

Posted on 2007-11-16
13
1,296 Views
Last Modified: 2013-11-26
I have a validate button, I want it to check the fields on the form and then open a new window with the list of errors.  The button.attributes.add("onclick".......) does not work, because that runs before the validate code has a chance to run, so the second window is blank.  Just wondering how to call the second window (kind of like a popup), after the validate code has ran.
0
Comment
Question by:sborchers
  • 5
  • 5
  • 2
  • +1
13 Comments
 
LVL 15

Expert Comment

by:spprivate
ID: 20300484
There is a cool solution here

http://www.codeproject.com/aspnet/asppopup.asp
http://www.eeeksoft.net/files/popuptest/Default.aspx

This is a popup user control which is pretty cool

Satheesh
0
 
LVL 35

Expert Comment

by:YZlat
ID: 20300706
use javcascript window.open
0
 

Author Comment

by:sborchers
ID: 20300773
Can you give me an example of javascript inside the click event of a button.
0
 
LVL 5

Expert Comment

by:ICINTRACOM
ID: 20300881
It would look like this -

<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Delete" OnClientClick="return confirm ( 'Confirm Delete!' )" Text="Delete"></asp:LinkButton>
0
 

Author Comment

by:sborchers
ID: 20301033
The button i'm using is not a link button, just a regular asp:button.  Once the button is click, it needs to run the validate code before opening up the 'popup' window.  I'm looking for validation first, then if needed open a popup window.
0
 
LVL 15

Expert Comment

by:spprivate
ID: 20301115
You can do like this
if (sent == true)
      {
      Page.RegisterClientScriptBlock("Myscript", "<script language='javascript'>alert('Email has been sent to ESL');</script>");

instead of alert you can have your window.open method.
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 35

Expert Comment

by:YZlat
ID: 20301124
button1.Attributes.Add("onclick", "javascript:window.open('your window address'); return false;");
0
 
LVL 15

Expert Comment

by:spprivate
ID: 20301196
Guys,
his point is that he has to execute a server side validation and based on that he has to show the errors in a different window.When you add attributes the client script will execute before the page ia post back.
So basically he has to first do the server validate and then call the javascript to open a separate window to show the error message. In my previous post,I am sending an email with smtp class and then showing a javascript alert.So your Page.RegisterClientScriptBlock will be the next statment after the server code.
HTH
0
 

Author Comment

by:sborchers
ID: 20301231
Thanks spprivate.  Here is code.

    Protected Sub butLabNext_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles butLabNext.Click
        Call ValidateRequest()
         more code.......
    End Sub

    Public Sub ValidateRequest()
        blnValid = True
        strErrors = ""
        If Trim(txtLabTestCode.Text) = "" Then
            'Missing Test
            blnvalid = False
            strLabErrors = "No Test was entered."
       end if
'Here is where i want to call another window.
    End Sub


thanks for the help!
0
 
LVL 15

Accepted Solution

by:
spprivate earned 500 total points
ID: 20302143
In the place you want to call the javascrpt put something like

if (blnvalid == false)
      {
      Page.RegisterClientScriptBlock("Myscript", "<script language='javascript'>window.open(http://site/errorpage.aspx?errormessage=strlaberrors',size of window);</script>");

Please check the javascript syntax and quotes.
HTH
0
 

Author Comment

by:sborchers
ID: 20314866
That code does work to open up a new on a postback.  If i'm using AJAX and the updatepanel, which is triggered by AsyncPostBackTrigger (button click), the call is not made.  I'm assuming since the entire page isn't getting refreshed that is why the call is not occuring.  Is there away to call that page, from an AsyncPostBackTrigger event?
0
 
LVL 15

Expert Comment

by:spprivate
ID: 20320941
Sorry,
I havent tried that in Ajax yet.So I dont have an idea
0
 

Author Closing Comment

by:sborchers
ID: 31409618
I didn't specify I was using AJAX controls, so the answer you gave worked fine.  It just doesn't work with AJAX.  Thanks for the help.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Loop not working 29 47
Remove greater than sign 3 46
Vb. Net application freezes 9 30
IIS Authorization for Web Service 2 22
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
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…

895 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

16 Experts available now in Live!

Get 1:1 Help Now