469,631 Members | 1,218 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,631 developers. It's quick & easy.

confirm box doesn't work in ascx

3
I am doing some validation in an ascx page. I have two textboxes. if user types char in the box, an alert box will be displayed, if user doesn't enter anything, a confirm box need to be displayed. Alert box works now, but confirm box doesn't work. my code:

Expand|Select|Wrap|Line Numbers
  1. Protected Sub btnContinue_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnContinue.Click        
  2.  
  3. If (textbox1.text <> "" And Not Regex.IsMatch(textbox1.text, "^\d+$")) Then
  4.             'display alert message here
  5. ...
  6. else 
  7.    '  add data to table
  8.  End if
  9.  
  10. in page_load 
  11.  
  12. Dim strScript As New StringBuilder
  13.  
  14.             strScript.Append("<script language=javascript>function confirmbox() ")
  15.             strScript.Append(" { ")
  16.             strScript.Append("if (document.getElementById(" & Me.textbox1.ClientID & ").value == '' ) ")
  17.             strScript.Append("   return confirm('This is a confirmbox');   ")
  18.             strScript.Append("        else ")
  19.             strScript.Append(" return true;  ")
  20.             strScript.Append("} ")
  21.             strScript.Append(" </script>")
  22.  
  23.             Dim clientScript As ClientScriptManager = Me.Page.ClientScript
  24.             If (Not clientScript.IsStartupScriptRegistered("qKey")) Then
  25.                 clientScript.RegisterStartupScript(Me.Page.GetType(), "qKey", strScript.ToString)
  26.               End If
  27.  
  28.  btnContinue.Attributes.Add("onclick", "return confirmbox();")

Please help. Thanks a lot
Sep 26 '08 #1
3 1710
nateraaaa
663 Expert 512MB
Try adding the Attribute for btnContinue in the Page_Load of your user control.

Nathan
Sep 26 '08 #2
atiger
3
Yes, I am having the button attributes in Page_load, the following code doesn't work, anything wrong?

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If (Not Page.IsPostBack) Then
If Me.textbox1.Text Is Nothing Or Me.textbox1.Text = "" Then
btnContinue.Attributes.Add("onclick", "return confirm(' message 1 ');")

ElseIf Me.textbox2.Text Is Nothing Or Me.textbox2.Text = "" Then
btnContinue.Attributes.Add("onclick", "return confirm(' message 2');")
ElseIf Me.textbox2.Text = "0" Then
btnContinue.Attributes.Add("onclick", "return confirm(' message 3' );")

End If
End If
Sep 26 '08 #3
nateraaaa
663 Expert 512MB
Do you have a runat="server" tag on your btnContinue button?

Nathan
Sep 26 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

5 posts views Thread by Logger | last post: by
reply views Thread by Maersa | last post: by
2 posts views Thread by JerryK | last post: by
4 posts views Thread by tfsmag | last post: by
8 posts views Thread by Eric | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.