Click here to Skip to main content
15,795,887 members
Please Sign up or sign in to vote.
4.50/5 (2 votes)
Hi all,

I am new in, 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>")
            txtCompany.Text = ""
            Txtemail.Text = ""
            Txttelephone.Text = ""
            Txtinfo.Text = ""
            lblStatus.Text = resulttosend
            Trace.Warn("ibSend_Click", "exception occured sending mail-->" & resulttosend)
        End If
    End Sub

1 solution

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>")


— Manfred
Share this answer
stellus 24-Sep-12 7:15am    
thanks for your reply , now its working fine...
Manfred Rudolf Bihy 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.


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

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900