473,800 Members | 2,518 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

JavaScript Add.Addtribute to an ASP.NET Button

I need to attach the following 2 little scripts to an ASP.NET Button. I am
having an issue with running both of the Attributes.Add. I can only get on
to work at once. I have also tried to put them both/either in the page_load,
but cannot get it to work.

TIA,

Steve Wofford
www.IntraRELY.com
SUEDO Code:
----------------------
User clicks btnPrint
Sc. 1
btnPrint.Attrib utes.Add("OnCli ck", "javascript:ret urn confirm('Are you sure
you want to print these checks?');")
removed records from the datagrid and redraws it w/o the checks records.
Sc. 2
btnPrint.Attrib utes.Add("oncli ck", "window.open('p rintCheckClient .exe',
1);")
Local vb.net client queries the db for the records that where removed from
the above datagrid.
ACTUAL CODE:
-----------------------
' Sc. 1
btnPrint.Attrib utes.Add("OnCli ck", "javascript:ret urn confirm('Are you sure
you want to print these checks?');")
Dim checkIdItem As DataGridItem
sqlChecks.Open( )
For Each checkIdItem In dgChecks.Items
Dim dgCheckbox As CheckBox = CType(checkIdIt em.Cells(0).Con trols(1),
CheckBox)
If dgCheckbox.Chec ked Then
Dim selectedCheckId = dgChecks.DataKe ys(checkIdItem. ItemIndex)
With cmdChecksPrintU pdate
..Parameters("@ checkId").Value = selectedCheckId
..Parameters("@ printed").Value = 2
End With
Try
Dim eNonQuery = cmdChecksPrintU pdate.ExecuteNo nQuery
With cmdChecksCount
..Parameters("@ printed").Value = globalPrinted
End With
dgChecks.Virtua lItemCount = cmdChecksCount. ExecuteScalar()
Catch ex As SqlClient.SqlEx ception
lblMessage.Text = "Unexplecte d error." + ex.Message
Finally
End Try
End If
Next
If dgChecks.Curren tPageIndex = 0 Then
dgChecks_fill(g lobalPrinted)
Else
If Math.Ceiling(dg Checks.VirtualI temCount / dgChecks.PageSi ze) <
dgChecks.PageCo unt Then
Dim currentPageInde x = dgChecks.Curren tPageIndex
Dim pageCount = dgChecks.PageCo unt
If currentPageInde x + 1 = pageCount Then
dgChecks.Curren tPageIndex = Math.Ceiling(dg Checks.VirtualI temCount /
dgChecks.PageSi ze) - 1
Dim topExclude = (dgChecks.Curre ntPageIndex) * dgChecks.PageSi ze
dgChecks_fill(t opExclude)
Else
Dim topExclude = (dgChecks.Curre ntPageIndex) * dgChecks.PageSi ze
dgChecks_fill(t opExclude)
End If
Else
Dim topExclude = (dgChecks.Curre ntPageIndex) * dgChecks.PageSi ze
dgChecks_fill(t opExclude)
End If
End If
' Sc. 2
btnPrint.Attrib utes.Add("oncli ck", "window.open('p rintCheckClient .exe',
1);")
End Sub
Nov 18 '05 #1
3 2269
Hi Steve,
Thank you for using MSDN Newsgroup! My name is Steven, and I'll be
assisting you on this issue.
From your description, you've a web page which has a button named
"btnPrint" and you'd like to add two "onclick" client side event for this
button, the first is to popup a messagebox to confirm the operation. Then
you want the page posted back to the server and do some Database
manipuliation operation, after that, you want to add the
"window.open('p rintCheckClient .exe)" to the btnPrint's "onclick" event.
If there is anything I misunderstood, please feel free to let me know.

As for the client side script and event. Each html control such as button
could only have one handler for a certain event. For example, for a button,
you could only set one function or script block for its "onclick" event one
time. As for your situation, I think you may set the btnPrint's "onclick"
event as "javascript:ret urn confirm('Are you sure
you want to print these checks?');" Then, put the database operation in the
btnPrint's serverside click event, and use the "Page.RegisterS tartupScript"
method to add a script block which will be executed right after the page is
loaded in the client again. For example:
private void btnPrint_Click( object sender, System.EventArg s e)
{
//add the database operation here
Page.RegisterSt artupScript("Op enPrintWindow", "<script
language='javas cript'>window.o pen('printpage' ,'_blank')</script>");

}
Also, to make it clearly, I've made a sample page to show the code logic.
You may try it out on your side to see whether it can help you on this
problem.

---------------------------------------aspx page
code--------------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>WebForm1 </title>
<meta name="GENERATOR " content="Micros oft Visual Studio.NET 7.0">
<meta name="CODE_LANG UAGE" content="Visual Basic 7.0">
<meta name="vs_defaul tClientScript" content="JavaSc ript">
<meta name="vs_target Schema"
content="http://schemas.microso ft.com/intellisense/ie5">

</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<table width="600" align="center">
<tr>
<td><FONT face="ËÎÌå">
<asp:Label id="lblMessage " runat="server"> </asp:Label></FONT></td>
<td>
<asp:Button id="btnPrint" runat="server"
Text="Print"></asp:Button></td>
</tr>
</table>
</form>
</body>
</HTML>

-----------------------------------------code-behind page class
code-----------------------------
public class Show : System.Web.UI.P age
{
protected System.Web.UI.W ebControls.Labe l lblMessage;
protected System.Web.UI.W ebControls.Butt on btnPrint;

private void Page_Load(objec t sender, System.EventArg s e)
{
// Put user code to initialize the page here
btnPrint.Attrib utes.Add("oncli ck","javascript :return confirm('Are you
sure you want to print these checks?');");
}

#region Web Form Designer generated code
override protected void OnInit(EventArg s e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeCompo nent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeCompo nent()
{
this.btnPrint.C lick += new System.EventHan dler(this.btnPr int_Click);
this.Load += new System.EventHan dler(this.Page_ Load);

}
#endregion

private void btnPrint_Click( object sender, System.EventArg s e)
{
//add the database operation here
//simulate the data operation
System.Threadin g.Thread.Sleep( 1000);
lblMessage.Text = "Database operation finish!";

Page.RegisterSt artupScript("Op enPrintWindow", "<script
language='javas cript'>window.o pen('printpage' ,'_blank')</script>");

}
}

If you feel the suggestion not quite suitable for your situation. Please
feel free to let me know and provide me more information on your
requirement so that I can make more effort on it.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 18 '05 #2
Worked like a charm...Thanks for you help!

Steve Wofford

"Steven Cheng[MSFT]" <v-******@online.m icrosoft.com> wrote in message
news:ut******** *****@cpmsftngx a08.phx.gbl...
Hi Steve,
Thank you for using MSDN Newsgroup! My name is Steven, and I'll be
assisting you on this issue.
From your description, you've a web page which has a button named
"btnPrint" and you'd like to add two "onclick" client side event for this
button, the first is to popup a messagebox to confirm the operation. Then
you want the page posted back to the server and do some Database
manipuliation operation, after that, you want to add the
"window.open('p rintCheckClient .exe)" to the btnPrint's "onclick" event.
If there is anything I misunderstood, please feel free to let me know.

As for the client side script and event. Each html control such as button
could only have one handler for a certain event. For example, for a button, you could only set one function or script block for its "onclick" event one time. As for your situation, I think you may set the btnPrint's "onclick"
event as "javascript:ret urn confirm('Are you sure
you want to print these checks?');" Then, put the database operation in the btnPrint's serverside click event, and use the "Page.RegisterS tartupScript" method to add a script block which will be executed right after the page is loaded in the client again. For example:
private void btnPrint_Click( object sender, System.EventArg s e)
{
//add the database operation here
Page.RegisterSt artupScript("Op enPrintWindow", "<script
language='javas cript'>window.o pen('printpage' ,'_blank')</script>");

}
Also, to make it clearly, I've made a sample page to show the code logic.
You may try it out on your side to see whether it can help you on this
problem.

---------------------------------------aspx page
code--------------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>WebForm1 </title>
<meta name="GENERATOR " content="Micros oft Visual Studio.NET 7.0">
<meta name="CODE_LANG UAGE" content="Visual Basic 7.0">
<meta name="vs_defaul tClientScript" content="JavaSc ript">
<meta name="vs_target Schema"
content="http://schemas.microso ft.com/intellisense/ie5">

</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<table width="600" align="center">
<tr>
<td><FONT face="ËÎÌå">
<asp:Label id="lblMessage " runat="server"> </asp:Label></FONT></td>
<td>
<asp:Button id="btnPrint" runat="server"
Text="Print"></asp:Button></td>
</tr>
</table>
</form>
</body>
</HTML>

-----------------------------------------code-behind page class
code-----------------------------
public class Show : System.Web.UI.P age
{
protected System.Web.UI.W ebControls.Labe l lblMessage;
protected System.Web.UI.W ebControls.Butt on btnPrint;

private void Page_Load(objec t sender, System.EventArg s e)
{
// Put user code to initialize the page here
btnPrint.Attrib utes.Add("oncli ck","javascript :return confirm('Are you
sure you want to print these checks?');");
}

#region Web Form Designer generated code
override protected void OnInit(EventArg s e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeCompo nent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeCompo nent()
{
this.btnPrint.C lick += new System.EventHan dler(this.btnPr int_Click);
this.Load += new System.EventHan dler(this.Page_ Load);

}
#endregion

private void btnPrint_Click( object sender, System.EventArg s e)
{
//add the database operation here
//simulate the data operation
System.Threadin g.Thread.Sleep( 1000);
lblMessage.Text = "Database operation finish!";

Page.RegisterSt artupScript("Op enPrintWindow", "<script
language='javas cript'>window.o pen('printpage' ,'_blank')</script>");

}
}

If you feel the suggestion not quite suitable for your situation. Please
feel free to let me know and provide me more information on your
requirement so that I can make more effort on it.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 18 '05 #3
Hi jean,
Thanks for your followup, as for your problem in VB.NET code, would you
please try the below code, this is a test page
I created using VB.NET which provide the same function as the C# one:

---------------------------------aspx page--------------------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>ButtonEv ent</title>
<meta name="GENERATOR " content="Micros oft Visual Studio .NET 7.1">
<meta name="CODE_LANG UAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaul tClientScript" content="JavaSc ript">
<meta name="vs_target Schema"
content="http://schemas.microso ft.com/intellisense/ie5">
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<table width="500" align="center">
<tr>
<td>
<asp:Button id="btnConfirm " runat="server" Text="Confirm
PostBack"></asp:Button>
</td>
</tr>
</table>
</form>
</body>
</HTML>
------------------------code behind page class---------------------
Public Class ButtonEvent
Inherits System.Web.UI.P age

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()

End Sub
Protected WithEvents btnConfirm As System.Web.UI.W ebControls.Butt on

'NOTE: The following placeholder declaration is required by the Web
Form Designer.
'Do not delete or move it.
Private designerPlaceho lderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeCompo nent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
btnConfirm.Attr ibutes.Add("onc lick", "javascript:ret urn
confirm('Are you sure?')")
End Sub

Private Sub btnConfirm_Clic k(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles btnConfirm.Clic k
Response.Write( "<br>You have clicked Yes!")
Page.RegisterSt artupScript("Po pUpWindow", "<script
language='javas cript'>window.o pen('http://www.asp.net')</script>")
End Sub
End Class

----------------------------------------------------------------------------
------------

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)



Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
1985
by: Trvl Orm | last post by:
I am working with 2 frames, Left and Right and the main code is in the left frame, which has been attached. Can someone please help me with this code. I am new to JavaScript and can't figure it out. What needs to happen is this: On the left frame you should have a series of buttons, which when pushed makes things happen on the right frame.
14
5486
by: tshad | last post by:
I posted this on the asp.net group, also. I wasn't sure whether this was an asp.net problem or a javascript problem. I have a page that was originally created from a program I found on the net that works well as an html page. It brings up a modal popup window that I have been trying to work out for days now and this was the closest I have been able to come. I added a little asp.net code and an asp.net button and cannot get it to
0
6439
by: Michelle Keys | last post by:
I am trying to call a print function to print a string from a database using javascript. Which is RC_DATA of Varchar2(2500). This is a javascript is not being used. I have a thing that needs to be modified: if(e.CommandName =="Print") { string parsedreceipt = null; parsedreceipt = DecodeReceipt (e.Item.Cells.Text); Session = parsedreceipt;
2
2846
by: Alex | last post by:
Hi all, I'm writing a small web application which searches a database based on a date field, and populates a datagrid control with the results. The datagrid control has selection buttons added to it to view additional details about the selected result (a second database query is triggered). I want this second query to pop up in a new window, the way it would if I used "window.open" in javascript. I've added a function in the
9
4923
by: tshad | last post by:
This is from my previous post, but a different issue. I have the following Javascript routine that opens a popup page, but doesn't seem to work if called from an asp.net button. It seems to work fine from a link. The button does bring up the popup window, but when I press the links on the page, it doesn't return or close the window. ****************************************************************************
4
3518
by: John Boy | last post by:
Hi, Can anyone help. This is really doing my nut in. 3 years ASP exp. and now doing .DOT which is a step in the wrong direction. Basically I am left with the code of a guy who has left. When I click a button on a pop-up window the javascript for that button click does a 'button.form.submit'. On the Server side there is a Button click event for this button, but for some reason it no longer fires. It worked fine before and everything...
8
3678
by: chrisdude911 | last post by:
how do i add video into a javascript web page with my own custom buttons?
16
1921
by: Tony Girgenti | last post by:
Hello. I just finished reading two articles about javascript here: http://msdn2.microsoft.com/en-us/library/bb332123(VS.80).aspx I tried some javascript testing in VS2005, SP1, VB , .NET 2.0, ASP.NET 2.0 on WIN XP Pro, SP2. It's real simple. I put a button on a page and coded the onClick in it like this:
2
37700
Frinavale
by: Frinavale | last post by:
JavaScript in ASP.NET Using JavaScript in ASP.NET pages can make your application seem to work faster and prevent unnecessary calls to the server. JavaScript can be used to perform client-side functionality in the user's browser without having to make calls back to the server; thus, saving resources. The following example demonstrates how you can use an ASP.NET button to trigger a JavaScript call which modifies an ASP.NET TextBox. ...
0
10273
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10250
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10032
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9085
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7574
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6811
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5469
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5603
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2944
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.