Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Messsage box

Status
Not open for further replies.

sthmpsn1

MIS
Sep 26, 2001
456
US
I am trying to add a popup window to a page that would prompt a confirmation message, I have a button called btndelcompany I added the following code to my page Page_Load sub, but nothing happens


btndelcompany.Attributes.Add("onClick","javascript: return confirm('Are You Sure You Want to Delete this Company?');")
 
I copied and pasted your code and it works perfectly for me. Do you have javascript turned off or some odd thing like that? That'l do donkey, that'l do
[bravo] Mark
 
This is my code

Public Sub Page_Load(Source as Object, E As EventArgs)


if Not IsPostBack Then
Dim dbconn As SqlConnection = New SqlConnection("server=AM1ST_FS1;database=Corporate;uid=sa;")
Dim selectCMD As SqlCommand = New SqlCommand()
Dim pnlPanel as Panel
Dim strPanelName as String
selectCMD.CommandText = "Select * from users where loginid = '" & request.servervariables("AUTH_USER") & "'"
selectCMD.Connection = dbconn
selectCMD.CommandTimeout = 30
dbconn.open
if selectCMD.ExecuteNonQuery() = 0 then
selectCMD.CommandText = "Select * from users where loginid = 'AM1ST_DOMAIN\" & request.servervariables("AUTH_USER") & "'"
end if
dbconn.close

Dim selectCMD1 As SqlCommand = New SqlCommand()
selectCMD1.CommandText = "Select * From company order by coname"
selectCMD1.Connection = dbconn
selectCMD1.CommandTimeout = 30
dbconn.open
company.DataSource = selectCMD1.ExecuteReader()
company.DataTextField = "coname"
company.DataValueField = "coname"
company.DataBind()
dbconn.close

Dim userDA As SqlDataAdapter = New SqlDataAdapter
userDA.SelectCommand = selectCMD
dbconn.Open()

Dim userDS As DataSet = New DataSet
userDA.Fill(userDS, "users")
dbconn.Close()
Session("cslevel") = userDS.tables("users").Rows(0).Item("cslevel")
Session("employee") = session("whosonline")
Session("whosonline") =userDS.tables("users").Rows(0).Item("loginid")
Session("loggedIn") = userDS.tables("users").Rows(0).Item("loginid")

Dim cookie as HttpCookie
cookie= new HttpCookie("ffutsym")
cookie.value = userDS.tables("users").Rows(0).Item("loginid")
response.appendcookie(cookie)

Dim today as string
Dim thedate as datetime
thedate = datetime.Now
today = thedate.Month

End If

btndelcompany.Attributes.Add("onClick","javascript: return confirm('Are You Sure You Want to Delete this Company?')")

End Sub


Here is my button code.
<asp:button ID=&quot;btndelcompany&quot; Text=&quot;Delete Company&quot; OnClick=&quot;delete_click&quot; runat=&quot;server&quot; />


It doesn't seem to work on any machine. Is there something I might be missing in a config file for my app??
 
what browser are you running in? Do you get any error messages? Not sure what else it could be since the button has nothing to do with the rest of the code there. That'l do donkey, that'l do
[bravo] Mark
 
well this is really wierd. if I create a blank page and put the code in the sub and just have a button on the page it works fine. In this page it isn't working though. I don't get why it isn't

I am using IE 6.0 Windows XP Pro
 
After doing some trouble shooting it seems that if I have validations on my page it doesn't work.
 
OH.. It may be then that it is running off to the server before it has a chance to fire the client side javascript. That'l do donkey, that'l do
[bravo] Mark
 
Hey Mark, I got a question for you with this code, how would I change it so my buttons say &quot;yes&quot; and &quot;no&quot; instead of &quot;ok&quot; and &quot;Cancel&quot;??

btndelcompany.Attributes.Add(&quot;onClick&quot;,&quot;javascript: return confirm('Are You Sure You Want to Delete this Company?');&quot;)
 
yeah I think that is exactly what it is doing How would you work around this?
 
I dunna.

Paul do you have a take on this? That'l do donkey, that'l do
[bravo] Mark
 
If you created a seperate Javascript function that prompted the alert How could you call a certain subroutine from ASP.NET to run from that function??
 
I got it Mark! In the actual web control as mine is a button you add the following.

CausesValidation=&quot;False&quot;

That fixed it!!
 
Oh I thought you needed to have them both run. Which I found a solution for also.

Here goes.

Add a label to the top of the form, but set the visibility to false. In the onclick event of the button put this in assuming the label is called &quot;LblScript&quot;

Dim sb As New stringBuilder()
sb.append(&quot;<script language=javascript>&quot;)
sb.Append(&quot;confirm('Are You Sure You Want to Delete this Company?');&quot;)
LblScript.Text = sb.ToString()


That'll do it. That'l do donkey, that'l do
[bravo] Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top