button event onClick and server-side function

Results 1 to 3 of 3

Thread: button event onClick and server-side function

  1. #1
    Sv Guest

    Default button event onClick and server-side function

    Hello to all!!!<BR>I have a problem and I can&#039t find an answer. I need to delete records from database MS SQL Server. In my main asp page I declare function<BR><BR>&#060;script language="JavaScript" runat=Server&#062;<BR>function DelRecords(Server,onClick)<BR>{<BR>var DBcon = Server.CreateObject("ADODB.Connection");<BR>DBcon. Open(Session("DBConString"));<BR>sql = "delete from test where FirstCol=&#039"+Request.Form("nameDel")+"&#039 and SecondCol=&#039"+Request.Form("surnameDel")+"&#039 ";<BR>DBcon.Execute(sql);<BR>DBcon.Close;<BR>}<BR> <BR>&#060;/script&#062;<BR><BR>Then in the same asp page I have a button and I want to assign that my function DelRecords to onClick of that button and write<BR><BR>&#060;input type="button" id="delBtn" value="Delete" onClick=&#039DelRecords()&#039&#062;<BR><BR>When I run it I see mistake that Object is not found. I think it&#039s connected to that my function is running at server side. But I don&#039t know how to fix it.<BR><BR>If I use<BR>&#060;input type="submit" id="delBtn" value="Delete"&#062; and do the same job with deleting in another asp pages with form&#039s method POST everything is working.<BR><BR>And if I write (in my main page) in asp tags<BR>&#060;% DelRecords() %&#062; with some parameters inside it works too. <BR><BR>But why it doesn&#039t work on onClick?<BR><BR>Thanks ahead.<BR><BR>

  2. #2
    Join Date
    Dec 1969

    Default RE: button event onClick and server-side function

    You won&#039t be able to call server-side code from the client or vice versa.<BR><BR>You could set a hidden text field called, say, txtAction, set it&#039s value to "Delete" in JavaScript, then submit the form. When the page is accessed, if this Request.Form("txtAction") is "Delete", then proceed with the delete.<BR><BR>Hope it helps.

  3. #3
    Sv Guest

    Default Thanks Ben!You're the first person(+)

    who explains me this thing in normal way.<BR><BR>Regards,Svetlana

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts