473,408 Members | 1,762 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Browser event from webform control

How do I make a web form control react to a client side event in the browser
THe onclick event to server based. I am looking for onclick event on the client
I need something like this from a webform button control
<input type=button onclick="return OK()>"><script language="javascript"
function OK(

return confirm("Delete News Item. OK?")

</script
But I need the server event also.
Nov 18 '05 #1
3 1149
Here's some server side code that outputs javascript similar to what you are
requesting:
myDeleteButton.Attributes.Add("onclick", _
"return confirm('Are you sure you want to delete?');")

In this example, the Delete button will post back only if the person
confirms they want to delete. Otherwise your server code is never called in
response to the button click.

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net
"Arne" <an*******@discussions.microsoft.com> wrote in message
news:66**********************************@microsof t.com...
How do I make a web form control react to a client side event in the browser. THe onclick event to server based. I am looking for onclick event on the client. I need something like this from a webform button control:
<input type=button onclick="return OK()>"><script language="javascript">
function OK()
{
return confirm("Delete News Item. OK?");
}
</script>
But I need the server event also.

Nov 18 '05 #2
Let's say your button tag looks like this:

<asp:button id="Button1" style="Z-INDEX: 103; LEFT: 62px; POSITION: absolute; TOP: 233px" runat="server"
Text="Do It"></asp:button>

Add the following line in the Page_Load procedure:

Button1.Attributes("OnClick") = "return OK();"

HTH
Nov 18 '05 #3
Hi

Since you are using a regular button ( not submit )

myBtn.Attributes.Add("onclick","confirmDel(" + iItemID + ")");

Client
function confirmDel(iItemID){
if(confirm("Delete item?")) location.replace("pageToGo.aspx?iItemID=" +
iItemID);
// Or if you want submit the form
//if(confirm("Delete item?")) document.forms[0].submit();
}

If you use submit/ image button just return true/false
function confirmDel(){
return confirm("Delete item?");
}

--
Best Regards
Vidar Petursson
==============================
Microsoft Visual: Scripting MVP 2000-2004
http://www.icysoft.com/
http://www.deus-x.com/ Instant e-commerce
http://www.microsoft.com/technet/scriptcenter/
Playground: http://213.190.104.211/ ( IE 5.5+ only )

No matter where you go there you are
==============================
"Arne" <an*******@discussions.microsoft.com> wrote in message
news:66**********************************@microsof t.com...
How do I make a web form control react to a client side event in the
browser.
THe onclick event to server based. I am looking for onclick event on the
client.
I need something like this from a webform button control:
<input type=button onclick="return OK()>"><script language="javascript">
function OK()
{
return confirm("Delete News Item. OK?");
}
</script>
But I need the server event also.

Nov 18 '05 #4

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

Similar topics

3
by: trint | last post by:
Ok, I have tried to do this with the System.Web.UI and can't find anything for the webform. It seems much easier for a Winform. Any help in trapping Webform keydown event and keyup event is...
3
by: Tim Thomas | last post by:
Hi, I am very new to .NET and am in the process of building my first web application. I will briefly describe what i am trying to achieve: I have a system where suppliers register their...
7
by: Tim T | last post by:
Hi, I have the need to use dynamically loaded user controls in a webform page. I have the controls loading dynamically, and that part works fine. this is the code used in a webform to dynamically...
1
by: Chirag Malvi | last post by:
hello all, I am developing the web application using ASP.net and VS.2003 IDE. here is the situation which i want to implement. 1) User is browsing some webform. I want to trap this event....
1
by: Souri Challa | last post by:
Hi all, Is there any way to pass a large amount of data from an asp.net form to another browser window opened through client script ? (i.e without using sessions ). Here is my scenario.I've a...
2
by: mg | last post by:
What code (javascript) will cause a WebForm to be submited (runatserver) whenever a new character is typed into a TextBox from the keyboard?
8
by: Paul | last post by:
Hi, In a class i built, i fire an event when a field changes. In a webform that has an instance of the class, the event (from the class) is fired and the code is executed. However, my webpage...
5
by: seal | last post by:
OK, I am trying to fire an event from a usercontrol that tells the page when a checkbox was clicked. Here is the control and when I try and wire up the page to catch the event, my event is not...
3
by: CodeRazor | last post by:
I have a user contol hosted in a webform. The user control interfaces with an http component. When the user control loads, a request is sent to the http component. It takes around 10 seconds...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...
0
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...
0
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...
0
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,...
0
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...

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.