|
Hi,
How do I fire a specific event when clicking on a buttin?
I have code in:
window.onbeforeunload = function()
{
...my code
}
I need to trigger/fire this event when the button is clicked.
Thanks
Brendan
|
|
|
|
|
Add an onclick="functionName();" to your input tag.
|
|
|
|
|
Hi,
Below is the code of my body tag. The checkForChange method is called twice, why is this? I only need it to be called once. What it needs to do is to check if a textbox was changed, if so then it must display a message, but the message needs to be displayed if the user wants to go to another page if data was changed.
<body onbeforeunload="checkForChange();" >
<input type="text" onchange="isDirty = true;" />
<input type="submit" name="btnCancel" value="Cancel" id="btnCancel" onclick="return checkForChange();" />
<br /><br /><br /><br />
<a href="Link.htm">LinkLinkLinkLinkLinkLinkLinkLink</a>
<script language="javascript" type="text/javascript">
var isDirty = false;
function checkForChange()
{
if (isDirty)
return confirm('Changes have been made.');
else
return true;
}
</script>
</body>
If the user clicks cancel, it should stay on the current page, but if it clicks ok, then it should move to the next page. Currently the massge boz is displayed twice, and it doesn't matter what is clicked it still goes to the next page (on the link that was clicked).
Please can someone help.
Thanks
Brendan
<div class="ForumMod">modified on Wednesday, February 13, 2008 5:35 AM</div>
|
|
|
|
|
The code below works fine in IE 6.0. Perhaps it can solve your problem.
<head>
<script type="text/javascript">
var isDirty = false;
function checkForChange() {
if (isDirty) {
alert("Changes have been made.");
}
}
function moveToNext() {
if (isDirty) {
if(confirm('Move to next page...')) {
var myLink = document.getElementById('myLink');
myLink.href='Link.htm';
myLink.click();
}
}
}
</script>
</head>
<body>
<input type="text" onchange="isDirty=true;" />
<input type="submit" name="btnCancel" value="Cancel" id="btnCancel" onclick="javascript:checkForChange();"/>
<br /><br /><br /><br />
<a id="myLink" href="javascript:moveToNext();">LinkLinkLinkLinkLinkLinkLinkLink</a>
</body>
|
|
|
|
|
Hi All
I am trying to allow one to three (3) files to be uploaded to a server, then send an email to the recipient for verification.
The files upload correctly and the email is sent, however it sends three emails for the one upload process.
What do I need to change in the code so that I only send one email for the complete process?
Any help would be appreciated.
Regards
Robert Caya
Here is the code for the process ...
default.aspx
]]>
<title>Document Upload and Email Verification
Document Upload and Email Form Sender
<asp:fileupload id="FileUpload1" cssclass="textSmall" runat="server" width="250px">
<asp:fileupload id="FileUpload2" cssclass="textSmall" runat="server" width="250px">
<asp:fileupload id="FileUpload3" cssclass="textSmall" runat="server" width="250px">
|
|
Your Name: | <asp:textbox id="txtName" cssclass="textSmall" width="241" runat="server"> | Your Email Address: | <asp:textbox id="txtEmail" cssclass="textSmall" width="241" runat="server"> | Your Comments: | <asp:textbox id="txtMessage" width="100%" runat="server" height="99" textmode="MultiLine" maxlength="400"> | | |
<asp:button id="Button1" cssclass="textSmall" runat="server" text="Send Now" onclick="Button1_Click">
<asp:button id="Button2" cssclass="textSmall" runat="server" text="Reset" onclick="Button2_Click">
| | <asp:label id="lblStatus" runat="server" enableviewstate="False"> | |
<asp:label id="Label1" cssclass="textSmall" runat="server">
|
|
<asp:requiredfieldvalidator id="RequiredFieldValidator1" runat="server">
ErrorMessage="You must enter your name." ControlToValidate="txtName">
<asp:requiredfieldvalidator id="RequiredFieldValidator2" runat="server">
ControlToValidate="txtEmail" ErrorMessage="You must enter your email address">
<asp:regularexpressionvalidator id="RegularExpressionValidator1" runat="server">
ControlToValidate="txtEmail" ErrorMessage="Please correct the format of your email to: example "someone@somewhere.com"."
ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*">
default.aspx.cs
using System;
using System.IO;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net.Mail;
public partial class _mailUpload : System.Web.UI.Page
{
protected void Button1_Click(object sender, EventArgs e)
{
string filepath = "d:\\Uploads";
HttpFileCollection uploadedFiles = Request.Files;
SmtpClient smtpClient = new SmtpClient();
MailMessage message = new MailMessage();
MailAddress fromAddress = new MailAddress(txtEmail.Text, txtName.Text);
for (int i = 0; i < uploadedFiles.Count; i++)
{
HttpPostedFile userPostedFile = uploadedFiles[i];
try
{
if (userPostedFile.ContentLength > 0)
{
Label1.Text += "File #" + (i + 1) + " ";
Label1.Text += "File Name: " + userPostedFile.FileName + " ";
Label1.Text += "File Size: " + userPostedFile.ContentLength + "kb";
userPostedFile.SaveAs(filepath + "\\" +
System.IO.Path.GetFileName(userPostedFile.FileName));
}
// Default is localhost or you can specify a host name or ipaddress of the email server
smtpClient.Host = "localhost";
//Default port is 25
smtpClient.Port = 25;
//From address will be given as a MailAddress Object
message.From = fromAddress;
// To address collection of MailAddress
message.To.Add("rob@mydomain.com");
message.Subject = "Client File Upload System";
// CC and BCC optional
// MailAddressCollection class is used to send the email to various users
// You can specify Address as new MailAddress("admin1@yoursite.com")
//message.CC.Add("admin1@yoursite.com");
//message.CC.Add("admin2@yoursite.com");
// You can specify Address directly as string
//message.Bcc.Add(new MailAddress("admin3@yoursite.com"));
//message.Bcc.Add(new MailAddress("admin4@yoursite.com"));
//Body can be Html or text format
//Specify true if it is html message
message.IsBodyHtml = true;
// Message body content
message.Body = txtMessage.Text + "
The following files have been uploaded to the server.
" + Label1.Text;
// Send SMTP mail
smtpClient.Send(message);
lblStatus.Text = "Your email has been successfully sent.
The following files have been uploaded to the server.";
}
catch (Exception Ex)
{
Label1.Text += "There was an error sending your files ... " + Ex.Message;
lblStatus.Text += "Your email failed to send correctly ... " + Ex.Message;
}
}
}
#region "Reset"
protected void Button2_Click(object sender, EventArgs e)
{
txtName.Text = "";
txtEmail.Text = "";
txtMessage.Text = "";
Label1.Text = "";
}
#endregion
}
|
|
|
|
|
Move this line out of the for loop.
// Send SMTP mail
smtpClient.Send(message);
-Steve
|
|
|
|
|
Hello!
We are going to need a component to help us with generating reports with charts etc and exporting to .xls, .pdf and word. I´ve worked with Active Reports before, and I'm a little familiar with Crystal Reports. Are there any not too pricey alternatives to these components that anyone would recommend?
/Regards Magnus
|
|
|
|
|
SQL Server Reporting Services (SSRS), comes out of the box with SQL Server.
|
|
|
|
|
Yeah, but we are using Oracle Thx for the tip though!
|
|
|
|
|
Hi all,
please how do I correct this error. page works fine on my local system but when upload to my server I keep getting this kind of error.
|
|
|
|
|
If you are using IIS then go to the "Configuration..." button on the "Virtual Directory" tab page. On the "Options" tab is a setting named "Enable Parent Paths".
|
|
|
|
|
Also make sure you are not trying to get to a location below the base of the website. IIS doesn't allow you to access areas outside of the folder designated to the site.
The best way to accelerate a Macintosh is at 9.8m/sec² - Marcus Dolengo
|
|
|
|
|
Hi,
I need help with confirming when exiting without saving.
I am using ASP.NET 2.0. I have an .aspx page with a couple of input controls. Then there is a submit button and a cancel button. I have a javascript method that checks if an input field has been changed or not. When the cancel button is clicked this javascript method is fired and displays a pop up message to the user. The thing that I am having difficult to implement is if data in the input was changed, but the user doesn't click the cancel button, but just clicks on another link to another page. If this is the case then I need the javascript method also to fire where the user go to a different page.
Please can someone advise?
Regards
Brendan
|
|
|
|
|
i have used onbeforeunload event to confirm leave, i.e.
window.onbeforeunload = function() { <br />
if (modified) return "Unsaved changes. Are you sure you want to leave?"<br />
}
|
|
|
|
|
Thanks for this, but I am not sure where to put this in.
Here is a basic representation of my code:
<html xmlns="http://www.w3.org/1999/xhtml>
<head>
<title></title>
<script language="javascript" type="text/javascript">
var isDirty = false;
function checkForChange(msg)
{
if (isDirty)
return confirm(msg);
else
return true;
}
</script>
</head>
<body>
<input type="text" onchange="isDirty = true;" />
<input type="submit" name="btnCancel" value="Cancel" id="btnCancel" onclick="return checkForChange('You have made changes to the data since last saving. If you continue, you will lose these changes.');" />
</body>
</html>
I hope you can help me on this.
Thanks
Brendan
|
|
|
|
|
Hi,
See the modified example below. I would suggest to use temporary functions to avoid javascript memory leaks. I hope this makes sense.
<html xmlns="http://www.w3.org/1999/xhtml"><br />
<head><br />
<title></title><br />
<br />
<script language="javascript" type="text/javascript"><br />
var isDirty = false;<br />
<br />
var default_message = "You have made changes to the data since last saving. If you continue, you will lose these changes."; <br />
<br />
var checkForChange = function(msg) {<br />
if (isDirty) return confirm( !msg ? default_message : msg ); <br />
}<br />
<br />
window.onbeforeunload = function() { <br />
return default_message; <br />
}<br />
</script><br />
<br />
</head><br />
<body><br />
<input type="text" onchange="isDirty = true;" /><br />
<input type="submit" name="btnCancel" value="Cancel" id="btnCancel" onclick="return checkForChange();" /><br />
</body><br />
</html><br />
|
|
|
|
|
Hi all
Whats the difference between the following script includes ?
<script type="text/javascript" src="script.js">
P.S Hardly got anything usefull from google.
Thanks a million !
<div class="ForumSig">Wisdom is often meant as the ability and desire to make choices that can gain approval in a long-term examination by many people.</div>
|
|
|
|
|
In theory, you should provide both attributes. So long as it works, there is no real difference.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Can u show me an example please ?
Thank You
Wisdom is often meant as the ability and desire to make choices that can gain approval in a long-term examination by many people.
|
|
|
|
|
Ive even found out that if one uses the following code block debugging does not always work !
// Dont always work !
function doSomthing()
{
// break point here
}
// Debugging works here
function doSomthing()
{
// break point here
}
Wisdom is often meant as the ability and desire to make choices that can gain approval in a long-term examination by many people.
|
|
|
|
|
In HTML 3.2 the language attribute was used. Now the type attribute should be used instead.
The language attribute was deprecated in HTML 4:
HTML 4.01 : The script element[^]
Experience is the sum of all the mistakes you have done.
|
|
|
|
|
i want to apply filter so that only txt,doc,rtf files are seen . Others are not seen . Please let me know .
|
|
|
|
|
Here[^]
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Hi dude...
try it...
=========================================================
function checkFileExtension(elem) {
var filePath = elem.value;
if(filePath.indexOf('.') == -1)
return false;
var validExtensions = new Array();
var ext = filePath.substring(filePath.lastIndexOf('.') + 1).toLowerCase();
validExtensions[0] = 'txt';
validExtensions[1] = 'doc';
validExtensions[2] = 'rtf';
for(var i = 0; i < validExtensions.length; i++) {
if(ext == validExtensions[i])
return true;
}
alert ('You Cant upload a '+ext.toUpperCase()+' file!');
return false;
}
============================================================
* and now use this line in your code behind (this line used in VB.Net!!!)
===========================================================
myfile.Attributes.Add("onchange", "return checkFileExtension(this);")
============================================================
be cool...
|
|
|
|
|
thanks . i dont want validation. I want that only specified say excel file is seen no other file is seen. when i click browse of the control.
|
|
|
|