Popup window in same page and not in am empty page

        I am new to ASP.NET and C #.I am creating a web page with dynamically created textboxes.I submit these textbox values into the database.Before I click the Submit button I would like to check whether all the all the textbox values are entered and if any of the textbox is empty I would like to show a popup window stating that "Kindly enter all the values"
        This function works for me.But this popup window does not appear in the same page and it pops up in an empty background page and once I click OK i come back to my original page.
        I would like to have the pop up  window in my original page where I click the Submit Button and not an empty page.
        Can anyone help me to achieve this.

I used the code below
  if (tb.Text == String.Empty)
                      Response.Write("<script language='javascript'>alert('Kindly enter all the values')</script>");
                       return ;

Open in new window

Who is Participating?
thats probably because you are using response.write.

instead of that, use a common function that registers the alert function you wish to use in code behind.

for vb function:

Public Sub AlertError(ByVal ErrorStr As String)
        System.Web.UI.ScriptManager.RegisterClientScriptBlock(Me.Page, Me.GetType(), "TestKey", "alert('" & ClearStrForJavaScript(ErrorStr) & "');", True)
End Sub
asudhaaAuthor Commented:
Thank for your answer.As you said the problem was due to response.write and with below code it works well

   string strScript = "<script language='JavaScript'>alert('Kindly enter all the values')</script>";
                        Page.RegisterStartupScript("PopUp", strScript);
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.