473,386 Members | 1,795 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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 1855
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

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

Similar topics

5
by: Logger | last post by:
Help, I’m trying to implement a confirm button on an asp.net page. I have it attached to a asp:button control. In the button1 click event I call the CreateConfirmBox subroutine. The Box comes...
0
by: Thanh Nguyen | last post by:
Hi everyone, I'm encountering a very weird problem, I have spent the last 3 days trying to figure out how to fix but there is still no clue. Here is the problem: I define 2 WebUserControls: -...
0
by: Maersa | last post by:
Hi all, i've got a control that has a button and when clicked on it would send a postback, all of this works fine when the control is placed on a webform (aspx) but doesn't work when placing it...
1
by: Sandy | last post by:
I have a repeater which shows Group names. (Skip this part if you want rather irrelevant) The groups are ordered and formatted: Parent ---Child ------Grand Child (okay start reading again...
0
by: KK | last post by:
Hi I have a main page called lobby.aspx. lobby have the main menu. below that I loads web user controls (ascx) according to the selected main menu (into a placeholder). Some of my ascx,...
2
by: JerryK | last post by:
I have a piece of asp.net code that sets up a call to a javascript function in a controls onclick event. This javascript function displays a confirm dialog and returns the results of the confirm...
4
by: tfsmag | last post by:
Okay, I have a project management app i'm writing and in the left hand menu i have a treeview control that is populated with each project... in child nodes under each project node I have an "edit"...
8
by: Eric | last post by:
I have a confirm alert before the user goes to a delete page, and it doesn't matter if the user clicks ok or cancel - they always go to the delete page. I have the following code: <a...
5
by: strikefiend | last post by:
Ok, I'm somewhat new to .NET C# language and am having a bit of trouble. I'm trying to run the javascript confirm() method from my ascx page but I'm currently using C# as the main language of the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.