This is a migrated thread and some comments may be shown as answers.

button in a radgrid that doesnt make a request in jquery

3 Answers 38 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Cihan
Top achievements
Rank 1
Cihan asked on 14 Oct 2012, 05:19 PM
Hi All,

I created a button in a radgrid with below code. When I try to reach the value in columns that is okay. I can make it.

But I try to make a request with these parameters on my web service. I get this error "property of value is null or undefined" at runtime.

Now I am thinking I create these buttons dynamically. Is that the reason I cant make a request?

Please help.

protected void rgGeneralSearch_ItemDataBound(object sender, GridItemEventArgs e)<br>        {<br><br>            if (e.Item is GridDataItem)<br>            {<br>                GridDataItem gridDataItem = (GridDataItem)e.Item;<br>                Button btnAdd =<br>                    (Button)gridDataItem["Add"].FindControl("btnAdd");<br>                RadNumericTextBox txtQuantity =<br>                    (RadNumericTextBox)gridDataItem["Quantity"].FindControl("txtQuantity");<br><br><br>                //btnAdd.Attributes["onclick"] = "btnAddClick('" + txtQuantity.ClientID + ", "+ rgGeneralSearch.MasterTableView.GetColumn("Code") + "')";<br>                btnAdd.Attributes["onclick"] = "btnAddClick('" + txtQuantity.ClientID + "', '"+ e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["Code"] +"')";<br>                //btnAdd.Attributes["href"] = "#";<br>                btnAdd.Attributes.Add("ajax", "");<br>            }<br>        }


function btnAddClick(Quantity, Code) {<br>    alert($get(Quantity).value);<br>    alert(Code);<br><br>    var SenderType = 1;<br>    var SenderId = 22;<br>    var ProductId = 333;<br>    var CustomerId = 99;<br>    var SalesmanId = 88;<br>    var DiscSpecial = 23;<br>    var TerminalNumber = 234;<br><br>    var webMethod = "http://localhost:5261/WS/Basket_WS.asmx/InsertBasket";     <br>    var parameters = "{'SenderType':'" + SenderType + "', 'SenderId':'" + SenderId + "', 'ProductId':'" + ProductId + "', 'CustomerId':'" + CustomerId + "', 'SalesmanId':'" + SalesmanId + "', 'Quantity':'" + 22 + "','DiscSpecial':'" + DiscSpecial + "','TerminalNumber':'" + TerminalNumber + "'}";   <br>    $.ajax({<br>        type: "GET",<br>        url: webMethod,<br>        data: parameters,<br>        contentType: "application/json; charset=utf-8",<br>        dataType: "json",<br>        success: OnGetSuccess,<br>        error: OnGetError<br>    });<br>}

3 Answers, 1 is accepted

Sort by
0
Radoslav
Telerik team
answered on 18 Oct 2012, 08:55 AM
Hello Cihan,

I tried to reproduce the described issue but to no avail. I am sending you a simple example based on your code snippet with a little modification. Please check it out and let me know if it helps you.
Looking forward for your reply.

Greetings,
Radoslav
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Cihan
Top achievements
Rank 1
answered on 19 Oct 2012, 08:48 PM
Hey Radoslav,

Sorry for my language. I am trying to do my best.

I am sending a pic from my project. I want to do some inserts when I click the button. Now, I am creating button in design time under the event rgGeneralSearch_ItemDataBound. What I try to make is that user will enter some value in text box and click the send button. then i will take some values from grid cells and textbox' value and insert all of them my table. here is the thing. give me some idea.. which way is simple and best?

Please give some idea.
My Best.
0
Radoslav
Telerik team
answered on 24 Oct 2012, 06:01 AM
Hello Cihan,

To achieve the desired functionality you could try handling the server side button’s click event. Into the handler you could find the GridDataItem from the button.NamingContainer (which is a GridDataItem) and extract needed values. After that you could insert them into your database and call the RadGrid.Rebind() method.

Please give it try and let me know if it helps you.

All the best,
Radoslav
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Ajax
Asked by
Cihan
Top achievements
Rank 1
Answers by
Radoslav
Telerik team
Cihan
Top achievements
Rank 1
Share this question
or