-1

I'm working on an asp.net app with bootstrap and jquery. In my "contact us view" I have button dropdown for choice the subject of the mail. When I click on an item of the list a label get the value in this is a jquery process. When I try to retrieve the label's data in my code behind in C# it seems that the value of the label has never been set with any value.

the asp label that I need value:

 <asp:Label ID="lblObjetTextOnServer" ClientIDMode="Static" runat="server" type ="text">Objet</asp:Label>

my jquery:

 $('.dropdown-menu li a').on('click', function () {       
        $("#lblObjetTextOnServer").val($(this).text());
        $("#lblObjetText").html($(this).text());

    });

My drop down menu:

<div class ="dropdown"> 
                <asp:Button ID="Btn_dll_objet" Class="btn btn-default dropdown-toggle" type ="button" data-toggle="dropdown" >Votre demande concerne : <span class ="caret"></span></asp:Button>                       
                <ul ID="dropdown-menu" class ="dropdown-menu" role ="menu" aria-labelledby="dropdownMenu1">
                    <li class ="dropdown-header">Informations et conventionnement</li>
                    <li><a tabindex="-1" href="#">Demande d'information</a></li>
                    <li><a tabindex="-1" href="#">Question sur le conventionnement en ligne</a></li>
                    <li><a tabindex="-1" href="#">Mise a jour de votre fiche partenaire</a></li>
                    <li role="separator" class="divider"></li>
                    <li class ="dropdown-header">Transactions</li>
                    <li><a tabindex="-1" href="#">Question / incident : transactions par débit en ligne</a></li>
                    <li><a tabindex="-1" href="#">Question / incident : transactions par ticket</a></li>
                    <li><a tabindex="-1" href="#">Question sur relevé ou paiement</a></li>
                    <li role="separator" class="divider"></li>
                    <li class ="dropdown-header">Autre</li>
                    <li><a tabindex="-1" href="#">J'ai une question sur un autre sujet</a></li>
                </ul>                         
            </div>

My code behind:

protected void Page_Load(object sender, EventArgs e)
        {

            if (!Page.IsPostBack)
            {       
                  string subj =((Label)lblObjetTextOnServer.FindControl("lblObjetTextOnServer")).Text;
            }
        }
SynozeN Technologies
  • 1,337
  • 1
  • 14
  • 19
BarryF
  • 89
  • 6
  • you are modifying a client-side text (in the browser). There is no magic which would reflect that in your server-side rendering. – earloc May 22 '17 at 12:43
  • @AlexanderClare Thanks I thought that use an asp label give me the possibility to pass the data in my server side – BarryF May 22 '17 at 12:45
  • No, such modifications won´t actually be reflected on the server. maybe a read on [forms / post](https://learn.microsoft.com/en-us/aspnet/web-pages/overview/ui-layouts-and-themes/4-working-with-forms) can help you to grasp the concepts needed for what you are trying to achieve. – earloc May 22 '17 at 12:48
  • Possible duplicate of [Accessing Asp.net controls using jquery (all options)](https://stackoverflow.com/questions/20227170/accessing-asp-net-controls-using-jquery-all-options) – Mina Gabriel May 22 '17 at 12:49
  • sorry, above link is for MVC. [This](https://www.codeproject.com/Articles/13628/Post-an-ASP-NET-WebForm-with-JavaScript-between-fr) seems more connected. – earloc May 22 '17 at 12:50
  • @Mina Gabriel: No, the OP doesn´t want to actually access a server-side rendered control, but expectes a client-side modification to be reflected on the server, hence not a dup! – earloc May 22 '17 at 12:51
  • Thanks @MinaGabriel and AlexanderClare but nothing works I try to find another way – BarryF May 22 '17 at 13:28

1 Answers1

1

Accessing asp controls are different use:

$('#<%= lblObjetTextOnServer.ClientID% >').val();
Mina Gabriel
  • 23,150
  • 26
  • 96
  • 124