Reputation: 53
I try set new value for input 'pid' attribute and get this, but I get null
.
I have this code in jquery:
$(".feauter-product-holder").click(function () {
$("#productsubject").attr("pid", $(this).find("input[type=hidden]").attr("id"));
});
and my code in HTML:
<div class='feauter-product-holder'>
<input type="hidden" id="3">
</div>
<asp:TextBox runat="server" ID="productsubject" pid=""></asp:TextBox></div>
$.ajax({
url: editor.config.saveSubmitURL,//the url to post at... configured in config.js
type: 'POST',
data: { servicename: "savedata", text: data, subject: $("#productsubject").val(), pid: $("input[id$='productsubject").attr("pid") },//editor.name contains the id of the current editable html tag
})
i edit this post i write wrong class div,but in my code is correct. when i call pid in ajax i get null
What should I do?
Upvotes: 0
Views: 131
Reputation: 8871
First of all remove "." from class name in DIV and then you can try like this :-
$(".feauter-product-holder").click(function () {
$("input[id$='productsubject']").attr("pid", $(this).find("input[type=hidden]").attr("id"));
});
While Handling with ASP control with Jquery you use like (Element ends with selector)
example :- $("input[id$='productsubject']")
.. $("#productsubject")
won't work .
Actually in ASP.NET if you use asp control with some ID, ASP.NET Naming container changes the control ID like ctl001_yourcontrolID
to avoid conflicts. Hence, in Jquery when you select a element by simply its ID(like $("#productsubject")
) , you will not get that element since its ID has been changed. to illustrate, you can inspect the asp control in Firebug or chrome's inspect element.
Hence when you write $("input[id$='productsubject']")
,it select the element whose ID ends with productsubject
.
Upvotes: 1
Reputation: 422
You have 2 problems - the class on the div is incorrect, and also .net will change the id of the text box.
Try
<div class="feauter-product-holder">
for the div.
If you are using .net 4 you can set ClientIDMode="Static" on the text box like this
<asp:TextBox runat="server" ID="productsubject" pid="" ClientIDMode="Static"></asp:TextBox></div>
Upvotes: 0
Reputation: 457
Your DIV can't be found because of a wrong css class call. Try:
<div class="feauter-product-holder">
Upvotes: 5