 |
| ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

March 10th, 2006, 03:56 PM
|
|
Friend of Wrox
|
|
Join Date: Jul 2003
Posts: 599
Thanks: 6
Thanked 3 Times in 3 Posts
|
|
Javascript return false won't stop post
Hi All,
Please exuse this post if it has been answered here multiple times. I have searched but not found.
I have a check box list that I want to put a javascript confirm function on. I can get the control to show the confirm message box but even if I hit the cancel button the page still posts. There is a Handles sub on the CBL that posts the page with the new value for the checkbox to the database. All of that is working fine.
In the code behind in If not IsPostBack:
Code:
Me.cblCompTypeID.Attributes.Add("onclick", _
"return theConfirm('Are you sure you want to change this selection ? \n\nChanging this selection will alter the inventory queries and reports for this rule.');")
The javascript function on the aspx page:
Code:
function theConfirm(theMessage)
{
if(confirm(theMessage))
{
return true;
}
else
{
return false;
}
}
In the view source for the page I see onclick="__doPostBack('cblCompTypeID$1','')" in all of the items for the check box list which looks like it fires the sub first and then the confirm message box. So even if Cancel is selected the page will post anyway.
Is there a way to remedy this? Or does anyone have any other suggestions for a different approach?
Your response is very much appreciated.
Thank you,
Richard
|
|

March 13th, 2006, 07:52 PM
|
|
Friend of Wrox
|
|
Join Date: Jul 2003
Posts: 599
Thanks: 6
Thanked 3 Times in 3 Posts
|
|
Was able to solve this problem with this code in the sub that handles the CheckBoxList
Dim theConfirm As String = "<script language='javascript'>confirm('Changing the rule groups will affect reports for this rule. Be very careful in assigning or unassigning groups.');</script>"
Page.RegisterClientScriptBlock("PopupScript", theConfirm)
|
|

March 14th, 2006, 12:17 AM
|
|
Friend of Wrox
|
|
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
|
|
Glad you got it resolved. Can you post all of the code? I would like to see how it works. Thanks.. Jim
|
|

March 14th, 2006, 12:59 AM
|
|
Authorized User
|
|
Join Date: Mar 2006
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I was workin on a similar kind of issue some time ago, I used Page.RegisterStartupScript method.
I had to produce a pop up window with a chart and related data on click of a button on a asp.net page.
I am providing the anonymized code. customize for your need.
Quote:
quote:
Public Class MyReports
Inherits System.Web.UI.Page
Dim item As Object
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not(Session("xxxxxxx") = "Authorized") Then
Response.Redirect("login.aspx")
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim strPop As String
Dim file As String
file = "chartmaker.aspx?chType=" & lst_ChType.SelectedValue & "&Table=" & lst_Table.SelectedValue & "&Values=" & lst_Values.SelectedValue & "&Categories=" & _
lst_Categories.SelectedValue & "&Series=" & lst_Series.SelectedValue
strPop = "<script language='javascript'>" & vbCrLf _
& "window.open('" & file & "','Report','menubar=1,status=1,scrollbars=1,resiz able=1')" & vbCrLf _
& "</script>" & vbCrLf
Page.RegisterStartupScript("Pop", strPop)
End Sub
End Class
|
Regards,
Sai Puli
|
|

March 14th, 2006, 06:28 PM
|
|
Friend of Wrox
|
|
Join Date: Jul 2003
Posts: 599
Thanks: 6
Thanked 3 Times in 3 Posts
|
|
Here's the entire Handles Sub with those two lines inserted. Was told that this was impossible but ran into this RegisterClientScriptBlock for the Page object and gave it a try. Its working so far. Actually does stop the Post on the Cancel button for the javascript confirm alert.
Code:
Sub saveComponentTypes(ByVal s As Object, ByVal e As EventArgs) Handles cblCompTypeID.SelectedIndexChanged
If ddlRuleID.SelectedIndex > 0 Then
Dim theConfirm As String = "<script language='javascript'>confirm('Changing the rule groups will affect reports for this rule. Be very careful in assigning or unassigning groups.');</script>"
Page.RegisterClientScriptBlock("PopupScript", theConfirm)
Dim Pass As Integer
Try
_oConn.Open()
Dim SQL As String = "DELETE FROM RuleComponentTypes WHERE RuleID = " & ddlRuleID.SelectedValue & ";"
Dim CMD As New SqlCommand(SQL, _oConn)
CMD.ExecuteNonQuery()
For Each i As ListItem In cblCompTypeID.Items
If i.Selected Then
Dim SQL2 As String = "INSERT INTO RuleComponentTypes (RuleID, CompTypeID, Status) VALUES (" & ddlRuleID.SelectedValue & ", " & i.Value & ", 1);"
Dim CMD2 As New SqlCommand(SQL2, _oConn)
CMD2.ExecuteNonQuery()
Else
Dim SQL3 As String = "DELETE FROM RuleComponents WHERE RuleID = " & ddlRuleID.SelectedValue & " AND CompTypeID = " & i.Value & ";"
Dim CMD3 As New SqlCommand(SQL3, _oConn)
CMD3.ExecuteNonQuery()
End If
Next
Catch ex As Exception
Session("Alert") = ex.Message
Finally
_oConn.Close()
Session("Confirm") = "The rule components have been saved"
End Try
Else
Session("Alert") = "Please select a rule from the list to configure."
End If
End Sub
|
|

March 15th, 2006, 12:28 AM
|
|
Friend of Wrox
|
|
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
|
|
And the javascript is the same as the original post? And you have this in the page load?
Quote:
quote:
Me.cblCompTypeID.Attributes.Add("onclick", _
"return theConfirm('Are you sure you want to change this selection ? \n\nChanging this selection will alter the inventory queries and reports for this rule.');")
|
Sorry to be a pain, but I am trying to get it to work on my test page. If it works for me I want to keep the code in case I need it in the future..
Thanks... Jim
|
|

March 15th, 2006, 01:10 PM
|
|
Friend of Wrox
|
|
Join Date: Jul 2003
Posts: 599
Thanks: 6
Thanked 3 Times in 3 Posts
|
|
Hi Jim,
No problem at all. No pain at all. I take it all back. Its not working now. I swear it was working. The confirm alert was coming up and I was clicking Cancel and it WOULD NOT POST. I even had SQL QA open and was querying to see if the changes were being posted to the database. It was working and now its not. I'm really at a loss here.
But to answer your question, I'm sure I had removed that Attributes.Add code from the Page Load.
Quote:
|
quote:Me.cblCompTypeID.Attributes.Add("onclick", _
|
Quote:
|
"return theConfirm('Are you sure you want to change this selection ? \n\nChanging this selection will alter the inventory queries and reports for this rule.');")
|
I also remember messing with some code something like this.
Code:
Dim theConfirm As String = "<script language='javascript'>function theConfirm(){if(confirm('Changing the rule groups will affect reports
for this rule. Be very careful in assigning or unassigning groups.')){return true;}else{return false;}}</script>"
Page.RegisterClientScriptBlock("PopupScript", theConfirm)
Ragglesfratenfrigglefunk!
Woe is me!
May be impossible. I sure thought it was working.
Sorry if I caused you any undue frustration.
Richard
|
|

March 15th, 2006, 02:40 PM
|
|
Friend of Wrox
|
|
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
|
|
Not causing me frustration at all.. I was glad to see you got it working and was curious.. I'm sorry to hear that it is not now. I will keep working on it. In the mean time.. maybe someone else can post a suggestion, or maybe a post in a javascript forum can shed some light. Let me know if you get anywhere, and I will do the same...
Jim
|
|

March 16th, 2006, 12:18 PM
|
|
Friend of Wrox
|
|
Join Date: Jul 2003
Posts: 599
Thanks: 6
Thanked 3 Times in 3 Posts
|
|
Hi Jim,
Thanks. I know it was working. I just don't know if I ended up doing a Control+Z for some reason before I actually posted the pages. I'll keep working on it myself and post if I find it working again.
Richard
|
|

March 16th, 2006, 02:25 PM
|
|
Friend of Wrox
|
|
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
|
|
Cool :)
|
|
 |