Jquery value to Asp.net Textbox

Hi , am trying to get the Selected value from a menu that is created with pure Jquery and CSS . I somehow tried to put the value in a html textbox , but when i make it runat="Server" , it's not putting any value in there. Please help me in this.

Here's the Part of a jquery code

this.chooseItem = function (item) {
          menu.kill();
          // edit this for your own custom function/callback:
            $('#selectmenu').val($(item).text());
     
          location.href = $(item).attr('href');
      };

Here's the html input box
<input type="text" id="selectmenu"
    />

Right now this code is working fine, but i want to get the value in the .net code behind so that i can pass it to a stored procedure.  Please let me know how can i pass the value to asp.net textbox.

I already tried  the below code for an asp.net textbox.  but it's not working.
<asp:TextBox ID="Test1" runat="server"></asp:TextBox>
 $('#<%= Test1.ClientID %>').val($(item).text());

I would appreciate your help.
gladstonesheebaAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

leakim971PluritechnicianCommented:
Modify the code to set a class to the selected value :

this.chooseItem = function (item) {
// remove the class for the previous selected item
         $(".selectedItem").removeClass(".selectedItem");
// add the class for the new one
         $(item).addClass(".selectedItem");
          menu.kill();
          // edit this for your own custom function/callback:
            $('#selectmenu').val($(item).text());
      
          location.href = $(item).attr('href');
      };

Open in new window


and use :

$("form").submit(function() {
  $('#<%= Test1.ClientID %>').val( $(".selectedItem").text() );
});

Open in new window

0
gladstonesheebaAuthor Commented:
Hi,
 Am sorry Little bit confusing to me.  what is that remove the class for the previous selected item and you've added the same thing again in the add class. Please let me know.
0
leakim971PluritechnicianCommented:
when you click/choose a new item you may have previous item with the class.
the goal is to find the item having the class selected before postback
so we remove the class by default and set it ONLY for the new item
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

gladstonesheebaAuthor Commented:
how does that help in setting the textbox text value to the selected item. I tried it but still it's not assigning the text to the asp.net textbox control.

Where do i put the form.submit function()?.
0
leakim971PluritechnicianCommented:
Don't forget I don't see your page.

>here do i put the form.submit function()?.

in

$(document).ready(function() {
   // here
});
0
gladstonesheebaAuthor Commented:
Attached is the Jquery file for the menu selection. It uses Jquery-1.3.2.min.js plugin  . Am totally new to jquery , and am just using this code that  i got from an internet website. Please let me know how can i modify this so that i need to get the selected value to the .net code behind.
JqueryMenu.docx
0
leakim971PluritechnicianCommented:
let the code as you find it.
if it's a plugin, I do the job you want it do or search an other one :)

I would like to see the way you use it and the place you get it. thanks
0
gladstonesheebaAuthor Commented:
Hi,
 This is the place where i get those code.
http://filamentgroup.com/lab/jquery_ipod_style_and_flyout_menus/

0
gladstonesheebaAuthor Commented:
I want the same  flyout menu , but i want it to be able to get the selected item in the  .net code behind.

Please help me on this.

Thanks
0
leakim971PluritechnicianCommented:
the code you produce should work (so forget my code). Try without the redirection to see it, so like this :
this.chooseItem = function (item) {
      menu.kill();
      // just to be sure it found the .net control :
      if( $('#<%= Test1.ClientID %>').length > 0 ) alert("found");
      // edit this for your own custom function/callback:
      $('#<%= Test1.ClientID %>').val( $(item).text() );
      //location.href = $(item).attr('href');
};

Open in new window

0
gladstonesheebaAuthor Commented:
Hi,
 I don't think its finding the .Net control . Is there anyother way to do that?
0
leakim971PluritechnicianCommented:
could you provide a live link ? or right click on the page and choose view source ?

> Is there anyother way to do that?
this is the good way to do that

you may have an error blocking javascript
0
gladstonesheebaAuthor Commented:
Please find the attached file for  the source code and the image of the aspx page.
If i select the menu, the value is in Html input box, but  not in the asp.net Textbox.
sourcefile.docx
0
leakim971PluritechnicianCommented:
I can't find the following in sourcefile.docx

this.chooseItem = function (item) {
      menu.kill();
      // just to be sure it found the .net control :
      if( $('#<%= Test1.ClientID %>').length > 0 ) alert("found");
      // edit this for your own custom function/callback:
      $('#<%= Test1.ClientID %>').val( $(item).text() );
      //location.href = $(item).attr('href');
};

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
gladstonesheebaAuthor Commented:
ok, i finally tried and i can get the selected value in to the asp.net textbox control . But when i view the source by right clicking on the page , and i see there is no text assigned to the Textbox controls. and i couldn't get the value from the asp.net Textbox. Please see the attached image.
menu.PNG
0
leakim971PluritechnicianCommented:
>ok, i finally tried and i can get the selected value in to the asp.net textbox control
good

>But when i view the source by right clicking on the page , and i see there is no text assigned to the Textbox controls. and i couldn't get the value from the asp.net Textbox.
by viewing the source with Internet Explorer you can't see the value

0
gladstonesheebaAuthor Commented:

ok , but when i click the asp.net button to get the value from the Textbox control , the value disappears . how to retain that selected value everytime  in the Textbox so that i can get it in the button_click event.
0
leakim971PluritechnicianCommented:
>ok , but when i click the asp.net button to get the value from the Textbox control

put return false; at the OnClientClick attribute of your button
0
gladstonesheebaAuthor Commented:
Like this?.
<asp:Button id="btnTest" runat="server" onClientClick="return false;" OnClick="btnTest_Cllick" />
0
leakim971PluritechnicianCommented:
you mean currently you button is like this :

<asp:Button id="btnTest" runat="server" OnClick="btnTest_Cllick" />

Open in new window


please post your page
0
gladstonesheebaAuthor Commented:
yes that's correct .

Protected void  btnTest_Click(object sender,EventArgs e)
{
string selectedvalue =Test1.Text;

}
0
leakim971PluritechnicianCommented:
with this code you do a postback to the server and you have some code clearng your textbox

0
gladstonesheebaAuthor Commented:
That's what i want to know how to retain the value for the textbox so that i can get it in button_click event.Please let me know.
0
leakim971PluritechnicianCommented:
post the code of your page
0
gladstonesheebaAuthor Commented:
protected void Page_Load(object sender, EventArgs e)
        {

           
            HtmlLink objLink = new HtmlLink();

            objLink.Attributes["rel"] = "Stylesheet";
            objLink.Attributes["type"] = "text/css";
            // objLink.Attributes["media"] = "screen";
            objLink.Href = "~/Scripts/menu.css";
            Page.Header.Controls.Add(objLink);

            HtmlLink controlcss = new HtmlLink();
            controlcss.Attributes["rel"] = "Stylesheet";
            controlcss.Attributes["type"] = "text/css";
            //controlcss.Attributes["media"] = "screen";
            controlcss.Href = "~/Scripts/theme1/ui.all.css";
            Page.Header.Controls.Add(controlcss);
            menustring.Text = Test1.Text;


            if (!IsPostBack)
            {
               
                GetDatafortheMenu();
            }
        }

protected void btnTest_Click(object sender, EventArgs e)
        {
            string value = Test1.Text;
           
           

        }
0
gladstonesheebaAuthor Commented:
For the jquery
in ASPX page
<script type="text/javascript">
        var ids = {
            txtmenu: "<%= Test1.ClientID %>"
           
        }
</script>

in External file Menu.js

this.chooseItem = function (item) {

          menu.kill();
         // to set the Selected value  text in asp.net textbox control
          $("#" + ids.txtmenu).val($(item).text());
      

          location.href = $(item).attr('href');
      };
0
leakim971PluritechnicianCommented:
sorry I was away.

You should remove this : location.href = $(item).attr('href');
because it ask to left the page

I understand your need to save and restore the selected item but I'm not sure you choose the good way to pass value between cthe lient side and the server, especially to save/restore state of .net control

check this articles to see if you found good info :
http://msdn.microsoft.com/en-us/library/ms972976.aspx
http://www.codeproject.com/KB/viewstate/retainingstate.aspx
http://www.telerik.com/community/forums/aspnet/docking/again-save-state-fo-dynamic-added-controls.aspx

I need to sleep a bit, see you later

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.