Browser event from webform control

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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.
 
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.
 
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
 
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
==============================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top