Click here to Skip to main content
11,565,743 members (47,185 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VS2005 VB.NET
Hi all,

I am new in vb.net, am doing one project which is have three modules such as home page, sign up page and finally contact us page using ASP.NET. My problem is contact us page that is, user can fill the contact details which i create in the contact us page.once user can able to fill the form and click to submit button, and then it as showing one popup window like "thank you for contacting us .we will get back to you shortly" (using script) find the below code) and i had to tap on ok button for the message to disappear. my question is when i clik ok button the page will need to go home page but its not going in my code. please find out the below code which i used in the contact us page. please give me a drop of solution which is very helpful for me...

my code is:

Protected Sub imgLogin_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles imgLogin.Click
        Dim resulttosend As String
        Dim subject As String = "  User Request:"
        Dim msgto As String = ConfigurationManager.AppSettings("contactus_email")
        Dim msgfrom As String = ConfigurationManager.AppSettings("SendMail_from")
        Dim msgcc As String = ""
        Dim msgbcc As String = ""
        Dim msgdesc As String
        msgdesc = "Hi Administrator,<br><br>" & _
                        "Name: " & Txtname.Text & "<br>" & _
                        "City: " & txtCompany.Text & "<br>" & _
                        "Tel: " & Txttelephone.Text & "<br>" & _
                        "Email: " & Txtemail.Text & "<br>" & _
                        "Additional Information: " & Txtinfo.Text & "<br>"
 

        Dim clsobj As clsCommon = New clsCommon
 
        resulttosend = clsobj.fnsendMail(msgfrom, msgto, msgcc, msgbcc, subject, msgdesc)
 
        If resulttosend = "" Then
            
            Response.Write("<script language="'javascript'">alert('Thank you for contacting us. We will get back to you shortly');</script>")
Response.Redirect("Index.aspx")
            txtCompany.Text = ""
            Txtemail.Text = ""
            Txttelephone.Text = ""
            Txtinfo.Text = ""
        Else
            lblStatus.Text = resulttosend
           
            Trace.Warn("ibSend_Click", "exception occured sending mail-->" & resulttosend)
        End If
    End Sub
Posted 22-Sep-12 0:29am
stellus1.1K

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

The code that is executing here is on the server side. Your Response.Write is sending HTML JavaScript code to the browser and the complete rest of your code inside the imgLogin_Click method is executed before the alert box is even displayed in the browser. This immediately brings my attention to a problem here:
Since Response.Redirect adds information to the HTTP headers it usually leads to an error when trying to Redirect the Reponse when one has already written to the stream. What you probably want is placing some code after the alert("..."); call that will make the browser navigate to your Index.asp like window.location.assign(url)[^].

Response.Write("<script language="'javascript'">alert('Thank you for contacting us. We will get back to you shortly'); window.location.assign('http://you.domain.xx/path/Index.asp');</script>")

Regards,

— Manfred
  Permalink  
v2
Comments
stellus at 24-Sep-12 7:15am
   
thanks for your reply , now its working fine...
Manfred R. Bihy at 24-Sep-12 7:20am
   
You're welcome!
If my solution helped you I'd appreciate if you voted for it and accepted it as a solution.

Cheers!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


Advertise | Privacy | Mobile
Web04 | 2.8.150624.2 | Last Updated 22 Sep 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100