PDA

Click to See Complete Forum and Search --> : use both Client and Server events on a server control


dialm4monkey
May 18th, 2005, 03:17 PM
Hi All -

I have a simple webform that caches a dataset until the user is finished editing all records then posts the changes back to the database.

I have 1 link button "btnHoldChanges" that holds changes to a dataset that is held in session. the server side OnClick handles updating the dataset. but I a want client onClick for an "Are You Sure?" the HTML for my link button looks like ... <asp:linkbutton id="btnHoldChanges" style="Z-INDEX: 111; LEFT: 8px; POSITION: absolute; TOP: 656px" onclick="return confirm('are you sure?')" runat="server">Hold Changes</asp:linkbutton> (hope that doesn't render)

as you can probably tell from this, I get an error. "return" is not a member of the page. that I can understand. so how do I get both server and client side script on a server control?

am I trying to have my Cake and eat it too?

nemaroller
May 18th, 2005, 03:56 PM
Remove the onclick attribute from your asp tag, and instead place it inside the Initialize section of your page (after the base.Initialize), or the Page_Load if not a postback.

btnHoldChanges.Attributes.Add("onclick","return confirm('Are you Sure?')");

The problem is the framework also uses the onclick event for LinkButtons especially (testing for validation, calling the doPostBack script ,etc). There is a way to do it frontside, but its much easier to do it on the backside so the framework renders the tag properly.

dialm4monkey
May 19th, 2005, 03:33 PM
Perfect, now is there a way to add the same function to the same event for multiple controls at once besides doing...

ctl1.Attributes.Add("someevent","somefunction")
ctl2.Attributes.Add("someevent","somefunction")
ctl3.Attributes.Add("someevent","somefunction")
ctl4.Attributes.Add("someevent","somefunction")
ctl5.Attributes.Add("someevent","somefunction")


like maybe... (pseudocode)

dim coll as collection

coll.add(ctl1)
coll.add(ctl2)
coll.add(ctl3)

coll.attributes.add("someevent","somefunction")