Is it possible to do something like this
$("#popupForgot").append("<asp:TextBox ID='emailTextF' runat='server' Width='200px' Text='" + $.cookie("forLogin") + "'></asp:TextBox>")
I need to append an asp.net element to a div tag which will have the cookie value as it's text. I've tried with the code above and it doesn't work.
Thank you in advance
It is not possible to do this, because asp:TextBox is rendered via server-side, whereas jQuery works on client-side.
However you can render your textbox with asp:TextBox control and then you can change its value with jQuery:
$("#emailTextF").text($.cookie("forLogin"));
UPDATE
It turns out that asp:TextBox rendered id isn't equal to id parameter (used inside asp:TextBox), try this:
$("#<%= emailTextF.ClientID %>").text($.cookie("forLogin"));
JQuery is, in the end, just JavaScript code. Javascript code runs in the client's browser.
ASP tags are a server side construct; they will be converted into <input type="Text"/> fields (or something else for multi-line textboxes) before they are sent to the client's browser.
These two are completely separate concepts that can't really interact with each other (directly).
If you want to add a textbox via JQuery it can't be an ASP textbox, it needs to be an HTML textbox. If you really do need to add an ASP textbox (you don't appear to need it from what you've shown here though) then you'll need to do a postback to the server to add it. (You could do that postback asynchronously via AJAX if you wanted.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With