Call code behind from JavaScript in c# -
I have a search page call "user" to show it when the user inputs the keyword and click on "search" Will call on some functions.
Now, I created a simple dropdownlist in the companiesdatagrid.ascx file:
& lt; ASP: UpdatePanel ID = "UpdatePanel1" runat = "server" & gt; & Lt; ContentTemplate & gt; & Lt; ASP: DropDownList ID = "DropDownList1" width = "200px" runat = "server" DataTextField = "ItemTypeName" DataValueField = "ItemTypeId" onchange = "CallServerMethod (it)" ValidationGroup = "vgLibItem" & gt; & Lt; / ASP: DropDownList & gt; & Lt; / ContentTemplate & gt; & Lt; Trigger & gt; & Lt; Asp: AsyncPostBackTrigger ControlID = "DropDownList1" EventName = "Selected Index Changed" / & gt; & Lt; / Trigger & gt;
I want to call it a javascript function which will call to work
Public Zero DropDownList1sel (object sender, EventArgs e) the address (CompaniesDatagridkascxkcs) behind the file
However, I call for a simple task that will test a simple case, the code behind :
Add Public Zero () {int a = 1; Int b = 3; Int c = a + b; }
Page_Load function (file CompanniesDatagrid.ascx.cs) to have:
protected void Page_Load (object sender, System.EventArgs e) { // Javascript literally clear this. Responses written record. Text = ""; If (! Page.IsPostBack) {if (Request.Form ["method"] == "add") {add (); Return; }}
And in companiesdatagrid.ascx I have this java script:
This only shows the "changed" warning, then "changed 2" and then "failure". I never received a warning of success, which means that I have never successfully added the () function to the code! Note that I tried to comment on all the URLs and get the same result! How to implement it correctly? I'm really from my way, please help! Thanks!
Change the first URL and check that it is not reaching the appropriate resource, then the data is not correct ..
var dataToSend = {Send1: 'Value1', Send2: 'Value2', Method: 'Add'}; "POST", url :: "known companiesdatagrid.ascx / methodName", data: dataToSend, contentType: "application / json; charset = utf-8", datatype: var = $ .ajax ({type, wherein " Json ", success: function (msg) {alert ('success');}, error: function () {warning (" error ");}});
Comments
Post a Comment