This really does work but it took me a ton of time to get there.  I was
using a couple of validation controls and they caused me a world of hurt
- finally got rid of them.

Following is some real-world, working code for you to analyze (from the
Page_Load event).  Know that you can cancel a server control click by
having the client-side function return false.  Returning true forwards
the event on to the server.

Jon Finley


            '-- Page script block
            Dim scriptString As String
            scriptString += "<script language=""JavaScript""> "

            scriptString += "function PreviewItem() "
            scriptString += "{ "
            scriptString += " if (document.Form1.txtPreview.value == '')
"
            scriptString += "   {alert('The item must be saved before it
can be previewed.'); "
            scriptString += "   } "
            scriptString += " else "
            scriptString += "   {newWin =
window.open(document.Form1.txtPreview.value); "
            scriptString += "   } "
            scriptString += "} "

            scriptString += "function OpenUploadWindow() "
            scriptString += "{ "
            scriptString += " if (document.Form1.txtFileFolder.value ==
'') "
            scriptString += "   {var UploadWin; "
            scriptString += "    UploadWin =
window.open('Upload.aspx?path=' +
document.Form1.txtTopParentContentItemFileFolder.value, 'UploadWindow',
'toolbar=no,width=500,height=300,status=no,scrollbars=no,resize=no,locat
ion=no'); "
            scriptString += "   } "
            scriptString += " else "
            scriptString += "   {var UploadWin; "
            scriptString += "    UploadWin =
window.open('Upload.aspx?path=' + document.Form1.txtFileFolder.value,
'UploadWindow',
'toolbar=no,width=500,height=300,status=no,scrollbars=no,resize=no,locat
ion=no'); "
            scriptString += "   } "
            scriptString += "} "

            scriptString += "function AddRole() "
            scriptString += "{ "
            scriptString += "  for(var a=(document.Form1.lstRoles.length
- 1);a>=0;a--) {"
            scriptString += "    if
(document.Form1.lstRoles.options[a].selected) {"
            scriptString += "      var itemIndex =
document.Form1.lstRoles.options[a].index; "
            scriptString += "      var newOption =
document.createElement('option'); "
            scriptString += "      newOption.text =
document.Form1.lstRoles.options[a].text; "
            scriptString += "      newOption.value =
document.Form1.lstRoles.options[a].value; "
            scriptString += "
document.Form1.lstRolesSelected.options.add(newOption);"
            scriptString += "
document.Form1.lstRoles.options.remove(itemIndex);"
            scriptString += "    } "
            scriptString += "  } "
            scriptString += "  sortLists(document.Form1); "
            scriptString += "  UpdateRoleIDs(); "
            scriptString += "} "

            scriptString += "function RemoveRole() "
            scriptString += "{ "
            scriptString += "  for(var
a=(document.Form1.lstRolesSelected.length - 1);a>=0;a--) {"
            scriptString += "    if
(document.Form1.lstRolesSelected.options[a].selected) {"
            scriptString += "      var itemIndex =
document.Form1.lstRolesSelected.options[a].index; "
            scriptString += "      var newOption =
document.createElement('option'); "
            scriptString += "      newOption.text =
document.Form1.lstRolesSelected.options[a].text; "
            scriptString += "      newOption.value =
document.Form1.lstRolesSelected.options[a].value; "
            scriptString += "
document.Form1.lstRoles.options.add(newOption);"
            scriptString += "
document.Form1.lstRolesSelected.options.remove(itemIndex);"
            scriptString += "    } "
            scriptString += "  } "
            scriptString += "  sortLists(document.Form1); "
            scriptString += "  UpdateRoleIDs(); "
            scriptString += "} "

            scriptString += "function UpdateRoleIDs() "
            scriptString += "{ "
            scriptString += "  var lstIDs = ''; "
            scriptString += "  for(var
a=0;a<document.Form1.lstRolesSelected.length;a++) {"
            scriptString += "    var lstIDs = lstIDs + ',' +
document.Form1.lstRolesSelected.options[a].value; "
            scriptString += "    document.Form1.txtRoleIDs.value =
lstIDs; "
            scriptString += "  } "
            scriptString += "} "

            scriptString += "function CheckRequiredInfo() "
            scriptString += "{ "
            scriptString += "  var reqItems = ''; "
            scriptString += "  if (document.Form1.txtHeading.value ==
'') "
            scriptString += "    reqItems = reqItems + 'Heading is
required.\n'; "
            scriptString += "  if (document.Form1.txtLinkLabel.value ==
'') "
            scriptString += "    reqItems = reqItems + 'Link Label is
required.\n'; "
            scriptString += "  if
(document.Form1.txtPublicItemDescription.value == '') "
            scriptString += "    reqItems = reqItems + 'Public
Description is required.\n'; "
            scriptString += "  if (document.Form1.txtEffectiveDate.value
== '') "
            scriptString += "    reqItems = reqItems + 'EffectiveDate is
required.\n'; "
            scriptString += "  if (document.Form1.txtSubmittedBy.value
== '') "
            scriptString += "    reqItems = reqItems + 'Submitted By is
required.\n'; "
            scriptString += "  if (reqItems == '') "
            scriptString += "    return true; "
            scriptString += "  else {"
            scriptString += "    alert('The content has not been saved.
The following errors were found: \n' + reqItems); "
            scriptString += "    return false;} "
            scriptString += "} "

            scriptString += "</script>"


            '-- Register script block on page
            If (Not IsClientScriptBlockRegistered("clientScript")) Then
                RegisterClientScriptBlock("clientScript", scriptString)
            End If

            Me.btnRoleRemove.Attributes.Add("onClick",
"RemoveRole();return false;")
            Me.btnRoleAdd.Attributes.Add("onClick", "AddRole(); return
false;")







> -----Original Message-----
> From: Matthew Small [mailto:[EMAIL PROTECTED]] 
> Sent: Thursday, September 26, 2002 2:12 PM
> To: dotnet
> Subject: RE: Adding javascript onlcikc event to a button 
> which already has one
> 
> 
> Hi,
>       I've been trying this and variations of this with no 
> success. Anybody else got any ideas?
> 
> Thanks for your help
> 
> Matthew Small
> IT Supervisor
> Showstopper National Dance Competitions
> 3660 Old Kings Hwy
> Murrells Inlet, SC 29576
> 843-357-1847
> http://www.showstopperonline.com
>  
> 
> -----Original Message-----
> From: Alex Dresko [mailto:[EMAIL PROTECTED]] 
> Sent: Thursday, September 26, 2002 2:03 PM
> To: dotnet
> Subject: RE: Adding javascript onlcikc event to a button 
> which already has one
> 
> Try something like this in your code..
> 
> myButton.Attributes["OnClick"} += "AnotherJavascriptFunction();";
> 
> Depending on what the existing OnClick code looks like, you 
> might have to do this in order to add another Javascript 
> function to the command. 
> 
> myButton.Attributes["OnClick"} += ";AnotherJavascriptFunction();";
> 
> Alex Dresko
> Three Point Oh!
> 
> 
> 
> -----Original Message-----
> From: Matthew Small [mailto:[EMAIL PROTECTED]] 
> Sent: Thursday, September 26, 2002 1:16 PM
> To: dotnet
> Subject: Adding javascript onlcikc event to a button which 
> already has one
> 
> 
> Hi -
>       I'm using ASP.NET(VB) webforms.  I want to add a small 
> javascript line that causes my button to change its value 
> when clicked upon - from "Submit Purchase" to "Please Wait" 
> so the form does not get clicked more than once when the user 
> is waiting for a response.
>       I've tried adding an attribute to the button in 
> question, and it does get there.  The problem is that the 
> button already has an onclick event line that overrides the 
> one that I want to use.  I've thought about using 
> onformsubmit, but I have the same problem there. Anybody got 
> any ideas?
> 
> Thanks
> 
> Matthew Small
> IT Supervisor
> Showstopper National Dance Competitions
> 3660 Old Kings Hwy
> Murrells Inlet, SC 29576
> 843-357-1847
> http://www.showstopperonline.com
>  
> 
> 
> 
> 
> ---
> You are currently subscribed to dotnet as: 
> [EMAIL PROTECTED] To unsubscribe send a blank email to 
> %%email.unsub%%
> 
> ---------
> Administrated by 15 Seconds : http://www.15Seconds.com
> List Archives/Search : http://local.15Seconds.com/search 
> Subscription Information : http://www.15seconds.com/listserv.htm
> Advertising Information: http://www.internet.com/mediakit/
> 
> 
> 
> 
> 
> 
> ---
> You are currently subscribed to dotnet as: 
> [EMAIL PROTECTED] To unsubscribe send a blank email 
> to %%email.unsub%%
> 
> ---------
> Administrated by 15 Seconds : http://www.15Seconds.com
> List Archives/Search : http://local.15Seconds.com/search 
> Subscription Information : http://www.15seconds.com/listserv.htm
> Advertising Information: http://www.internet.com/mediakit/
> 
> 
> 
> 
> 
> 
> ---
> You are currently subscribed to dotnet as: 
> [EMAIL PROTECTED] To unsubscribe send a blank email to 
> %%email.unsub%%
> 
> ---------
> Administrated by 15 Seconds : http://www.15Seconds.com
> List Archives/Search : http://local.15Seconds.com/search 
> Subscription Information : http://www.15seconds.com/listserv.htm
> Advertising Information: http://www.internet.com/mediakit/
> 
> 
> 

---
You are currently subscribed to dotnet as: [email protected]
To unsubscribe send a blank email to [EMAIL PROTECTED]

---------
Administrated by 15 Seconds : http://www.15Seconds.com
List Archives/Search : http://local.15Seconds.com/search
Subscription Information : http://www.15seconds.com/listserv.htm
Advertising Information: http://www.internet.com/mediakit/


Reply via email to