Get HTML dynamic input value ASP.NET -


i'm using jquery's autocomplete on asp.net dropdownlist, user can select value , submit entry db. must able type in value, , can't seem able access value in code behind.

heres jquery:

(function ($) { $.widget("ui.combobox", {     _create: function () {         var self = this,                 select = this.element.hide(),                 selected = select.children(":selected"),                 value = selected.val() ? selected.text() : "";         var input = this.input = $("<input id='txtoptvalue'>")                 .insertafter(select)                 .val(value)                 .autocomplete({                     delay: 0,                     minlength: 0,                     source: function (request, response) {                         var matcher = new regexp($.ui.autocomplete.escaperegex(request.term), "i");                         response(select.children("option").map(function () {                             var text = $(this).text();                             if (this.value && (!request.term || matcher.test(text)))                                 return {                                     label: text.replace(                                         new regexp(                                             "(?![^&;]+;)(?!<[^<>]*)(" +                                             $.ui.autocomplete.escaperegex(request.term) +                                             ")(?![^<>]*>)(?![^&;]+;)", "gi"                                         ), "<strong>$1</strong>"),                                     value: text,                                     option:                                 };                         }));                     },                     select: function (event, ui) {                         ui.item.option.selected = true;                         self._trigger("selected", event, {                             item: ui.item.option                         });                     },                     change: function (event, ui) {                         if (!ui.item) {                             var matcher = new regexp("^" + $.ui.autocomplete.escaperegex($(this).val()) + "$", "i"),                                 valid = false;                             select.children("option").each(function () {                                 if ($(this).text().match(matcher)) {                                     this.selected = valid = true;                                     return false;                                 }                             });                             if (!valid) {                                 // remove invalid value, didn't match                                 //$(this).val("");                                // select.val("");                                // input.data("autocomplete").term = "";                                 return false;                             }                         }                     }                 })                 .addclass("ui-widget ui-widget-content ui-corner-left");          input.data("autocomplete")._renderitem = function (ul, item) {             return $("<li></li>")                     .data("item.autocomplete", item)                     .append("<a>" + item.label + "</a>")                     .appendto(ul);         };          this.button = $("<button type='button'>&nbsp;</button>")                 .attr("tabindex", -1)                 .attr("title", "show items")                 .insertafter(input)                 .button({                     icons: {                         primary: "ui-icon-triangle-1-s"                     },                     text: false                 })                 .removeclass("ui-corner-all")                 .addclass("ui-corner-right ui-button-icon")                 .click(function () {                     // close if visible                     if (input.autocomplete("widget").is(":visible")) {                         input.autocomplete("close");                         return;                     }                      // work around bug (likely same cause #5265)                     $(this).blur();                      // pass empty string value search for, displaying results                     input.autocomplete("search", "");                     input.focus();                 });     },      destroy: function () {         this.input.remove();         this.button.remove();         this.element.show();         $.widget.prototype.destroy.call(this);     } }); })(jquery); 

so takes dropdownlist, hides it, creates input field acting select , enables me type in values.. dropdownlist:

            <asp:formview id="frmcreateoptionvalue" runat="server" datakeynames="optionvalueid"             datasourceid="optionsetvalues_ds" defaultmode="insert"              oniteminserting="frmcreateoptionvalue_iteminserting">             <insertitemtemplate>                 <table border="0" cellpadding="0" cellspacing="0" id="id-form">                     <tr>                         <th>                             add option set value:                         </th>                         <td>                             <div class="ui-widget" runat="server" id="addoptvalue">                                 <asp:dropdownlist id="ddladdoptionvalue" runat="server" clientidmode="static" datasourceid="optionvalues_ds"                                     datatextfield="name" datavaluefield="optionvalueid" appenddatabounditems="true"                                     selectedvalue='<%# bind("optionvalueid") %>'>                                     <asp:listitem value="" text="select one..." />                                 </asp:dropdownlist>                                 &nbsp;                                 <asp:objectdatasource id="optionvalues_ds" runat="server" oldvaluesparameterformatstring="original_{0}"                                     selectmethod="getdataby1" typename="purekbbdatasettableadapters.tbloptionvaluetableadapter">                                     <selectparameters>                                         <asp:querystringparameter name="oid" querystringfield="optionsetid" type="int32" />                                     </selectparameters>                                 </asp:objectdatasource>                             </div>                         </td>                         <td>                             <asp:linkbutton id="insertbutton" runat="server" causesvalidation="true" commandname="insert"                                 cssclass="form-submit" />                         </td>                     </tr>                 </table>             </insertitemtemplate>         </asp:formview> 

and when user inserts item:

protected void optionsetvalues_ds_inserting(object sender, objectdatasourcemethodeventargs e) {     // if value doesn't exist, create     if (e.inputparameters["optionvalueid"] == null)     {         // !!!! cannot find html input , save value         string ovname = ((textbox)frmcreateoptionvalue.findcontrol("txtoptvalue")).text;         int ovoptionid = convert.toint32(request.querystring["optionsetid"]);          tbloptionvaluetableadapter t = new tbloptionvaluetableadapter();         int ovid = convert.toint32(t.insertquery(ovoptionid, ovname, 0, ""));           e.inputparameters["optionvalueid"] = ovid;     } } 

is stuck, how can value html input field generated in jquery?

how can achieved, it's killing me ;)

you can value of text box using javascript , save in hidden field read hidden field value code behind

put inside javascript

$('#hiddenfieldid').val($('#txtoptvalue').val()); 

then code behind

protected void optionsetvalues_ds_inserting(object sender, objectdatasourcemethodeventargs e) {     // if value doesn't exist, create    if (e.inputparameters["optionvalueid"] == null)    {        // !!!! cannot find html input , save value       string ovname = ((hiddenfield)frmcreateoptionvalue.findcontrol("hiddenfieldid")).value;       int ovoptionid = convert.toint32(request.querystring["optionsetid"]);        tbloptionvaluetableadapter t = new tbloptionvaluetableadapter();       int ovid = convert.toint32(t.insertquery(ovoptionid, ovname, 0, ""));         e.inputparameters["optionvalueid"] = ovid;    } } 

Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

c# - SharpSVN - How to get the previous revision? -

php cli reading files and how to fix it? -