how to get the text that has been selected from listitem of an unordered list in content page in asp.net












0















I need to know which listitem is selected from the unordered list which is there in the master page.



So basically when i click on any list item from the content page i need to know the is of the item that is clicked and perform some action.



i tried the following code but i am not able to add the click action and get the id of the selected list.



Control list = this.Master.FindControl("mainsection").FindControl("maindiv").FindControl("sideNav").FindControl("sideNavMenu");


Please help me



Edited code :



<ul id = "sortable1">
<li id = "Coffee">Coffee</li>
<li id = "tea">Tea
<ul>
<li id = "Black tea">Black tea</li>
<li id = "green tea">Green tea</li>
</ul>
</li>
<li id = "Milk">Milk</li>

<li style="display: list-item;" class="emptyMessage">No more contacts available</li></ul>









share|improve this question




















  • 1





    i would say better to use jQuery for this find this fiddle and then follow @Karan 's idea..

    – Curiousdev
    Nov 27 '18 at 8:50








  • 1





    On click of list item you can store value in some hidden field and on server side simply get value from that field.

    – Karan
    Nov 27 '18 at 8:50






  • 1





    When i see this nested FindControl monster i recommend to use a property in your master like SideNavMenu. Then you just need to cast the Master to the actual type and you can access it. Your approach can break easily in future if you change the structure minimally

    – Rango
    Nov 27 '18 at 8:51








  • 1





    @ashish: Search for "Content page interacts with master page" here: codeproject.com/Articles/36055/…

    – Rango
    Nov 27 '18 at 9:14






  • 1





    @ashish find updated FIDDLE just add e.stopPropagation(); and add e as parameter in click invoke function.. read more about e.stopPropagation(); HERE

    – Curiousdev
    Nov 28 '18 at 7:02


















0















I need to know which listitem is selected from the unordered list which is there in the master page.



So basically when i click on any list item from the content page i need to know the is of the item that is clicked and perform some action.



i tried the following code but i am not able to add the click action and get the id of the selected list.



Control list = this.Master.FindControl("mainsection").FindControl("maindiv").FindControl("sideNav").FindControl("sideNavMenu");


Please help me



Edited code :



<ul id = "sortable1">
<li id = "Coffee">Coffee</li>
<li id = "tea">Tea
<ul>
<li id = "Black tea">Black tea</li>
<li id = "green tea">Green tea</li>
</ul>
</li>
<li id = "Milk">Milk</li>

<li style="display: list-item;" class="emptyMessage">No more contacts available</li></ul>









share|improve this question




















  • 1





    i would say better to use jQuery for this find this fiddle and then follow @Karan 's idea..

    – Curiousdev
    Nov 27 '18 at 8:50








  • 1





    On click of list item you can store value in some hidden field and on server side simply get value from that field.

    – Karan
    Nov 27 '18 at 8:50






  • 1





    When i see this nested FindControl monster i recommend to use a property in your master like SideNavMenu. Then you just need to cast the Master to the actual type and you can access it. Your approach can break easily in future if you change the structure minimally

    – Rango
    Nov 27 '18 at 8:51








  • 1





    @ashish: Search for "Content page interacts with master page" here: codeproject.com/Articles/36055/…

    – Rango
    Nov 27 '18 at 9:14






  • 1





    @ashish find updated FIDDLE just add e.stopPropagation(); and add e as parameter in click invoke function.. read more about e.stopPropagation(); HERE

    – Curiousdev
    Nov 28 '18 at 7:02
















0












0








0








I need to know which listitem is selected from the unordered list which is there in the master page.



So basically when i click on any list item from the content page i need to know the is of the item that is clicked and perform some action.



i tried the following code but i am not able to add the click action and get the id of the selected list.



Control list = this.Master.FindControl("mainsection").FindControl("maindiv").FindControl("sideNav").FindControl("sideNavMenu");


Please help me



Edited code :



<ul id = "sortable1">
<li id = "Coffee">Coffee</li>
<li id = "tea">Tea
<ul>
<li id = "Black tea">Black tea</li>
<li id = "green tea">Green tea</li>
</ul>
</li>
<li id = "Milk">Milk</li>

<li style="display: list-item;" class="emptyMessage">No more contacts available</li></ul>









share|improve this question
















I need to know which listitem is selected from the unordered list which is there in the master page.



So basically when i click on any list item from the content page i need to know the is of the item that is clicked and perform some action.



i tried the following code but i am not able to add the click action and get the id of the selected list.



Control list = this.Master.FindControl("mainsection").FindControl("maindiv").FindControl("sideNav").FindControl("sideNavMenu");


Please help me



Edited code :



<ul id = "sortable1">
<li id = "Coffee">Coffee</li>
<li id = "tea">Tea
<ul>
<li id = "Black tea">Black tea</li>
<li id = "green tea">Green tea</li>
</ul>
</li>
<li id = "Milk">Milk</li>

<li style="display: list-item;" class="emptyMessage">No more contacts available</li></ul>






c# asp.net






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 28 '18 at 7:02







ashish

















asked Nov 27 '18 at 8:41









ashishashish

258




258








  • 1





    i would say better to use jQuery for this find this fiddle and then follow @Karan 's idea..

    – Curiousdev
    Nov 27 '18 at 8:50








  • 1





    On click of list item you can store value in some hidden field and on server side simply get value from that field.

    – Karan
    Nov 27 '18 at 8:50






  • 1





    When i see this nested FindControl monster i recommend to use a property in your master like SideNavMenu. Then you just need to cast the Master to the actual type and you can access it. Your approach can break easily in future if you change the structure minimally

    – Rango
    Nov 27 '18 at 8:51








  • 1





    @ashish: Search for "Content page interacts with master page" here: codeproject.com/Articles/36055/…

    – Rango
    Nov 27 '18 at 9:14






  • 1





    @ashish find updated FIDDLE just add e.stopPropagation(); and add e as parameter in click invoke function.. read more about e.stopPropagation(); HERE

    – Curiousdev
    Nov 28 '18 at 7:02
















  • 1





    i would say better to use jQuery for this find this fiddle and then follow @Karan 's idea..

    – Curiousdev
    Nov 27 '18 at 8:50








  • 1





    On click of list item you can store value in some hidden field and on server side simply get value from that field.

    – Karan
    Nov 27 '18 at 8:50






  • 1





    When i see this nested FindControl monster i recommend to use a property in your master like SideNavMenu. Then you just need to cast the Master to the actual type and you can access it. Your approach can break easily in future if you change the structure minimally

    – Rango
    Nov 27 '18 at 8:51








  • 1





    @ashish: Search for "Content page interacts with master page" here: codeproject.com/Articles/36055/…

    – Rango
    Nov 27 '18 at 9:14






  • 1





    @ashish find updated FIDDLE just add e.stopPropagation(); and add e as parameter in click invoke function.. read more about e.stopPropagation(); HERE

    – Curiousdev
    Nov 28 '18 at 7:02










1




1





i would say better to use jQuery for this find this fiddle and then follow @Karan 's idea..

– Curiousdev
Nov 27 '18 at 8:50







i would say better to use jQuery for this find this fiddle and then follow @Karan 's idea..

– Curiousdev
Nov 27 '18 at 8:50






1




1





On click of list item you can store value in some hidden field and on server side simply get value from that field.

– Karan
Nov 27 '18 at 8:50





On click of list item you can store value in some hidden field and on server side simply get value from that field.

– Karan
Nov 27 '18 at 8:50




1




1





When i see this nested FindControl monster i recommend to use a property in your master like SideNavMenu. Then you just need to cast the Master to the actual type and you can access it. Your approach can break easily in future if you change the structure minimally

– Rango
Nov 27 '18 at 8:51







When i see this nested FindControl monster i recommend to use a property in your master like SideNavMenu. Then you just need to cast the Master to the actual type and you can access it. Your approach can break easily in future if you change the structure minimally

– Rango
Nov 27 '18 at 8:51






1




1





@ashish: Search for "Content page interacts with master page" here: codeproject.com/Articles/36055/…

– Rango
Nov 27 '18 at 9:14





@ashish: Search for "Content page interacts with master page" here: codeproject.com/Articles/36055/…

– Rango
Nov 27 '18 at 9:14




1




1





@ashish find updated FIDDLE just add e.stopPropagation(); and add e as parameter in click invoke function.. read more about e.stopPropagation(); HERE

– Curiousdev
Nov 28 '18 at 7:02







@ashish find updated FIDDLE just add e.stopPropagation(); and add e as parameter in click invoke function.. read more about e.stopPropagation(); HERE

– Curiousdev
Nov 28 '18 at 7:02














1 Answer
1






active

oldest

votes


















0














Add <asp:HiddenField ID="hdnListId" runat="server"></asp:HiddenField> in your html. Give clickable class to each li you want to save id.



Add following javascript.



$(function() {    
$("li.clickable").click(function() {
$('#' + '<%=hdnListId.ClientID%>').val(this.id);
});
});


On server side, You can simply get value from hdnListId.Value






share|improve this answer
























  • Hi Karan this works only for the first click but when i select second item from the list it doesnt show the value

    – ashish
    Nov 27 '18 at 9:11











  • You can check with debugger in javascript code for second click whether it is triggering $("li.clickable").click(function() or not.

    – Karan
    Nov 27 '18 at 9:14











  • I think the reason is because i have an update panel. How can i do this with update panel

    – ashish
    Nov 27 '18 at 9:15











  • You have to put hdnListId inside Updated panel

    – Karan
    Nov 27 '18 at 9:17











  • i tried that but that didnt work. I think the function is only getting executed once

    – ashish
    Nov 27 '18 at 10:33











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53495669%2fhow-to-get-the-text-that-has-been-selected-from-listitem-of-an-unordered-list-in%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Add <asp:HiddenField ID="hdnListId" runat="server"></asp:HiddenField> in your html. Give clickable class to each li you want to save id.



Add following javascript.



$(function() {    
$("li.clickable").click(function() {
$('#' + '<%=hdnListId.ClientID%>').val(this.id);
});
});


On server side, You can simply get value from hdnListId.Value






share|improve this answer
























  • Hi Karan this works only for the first click but when i select second item from the list it doesnt show the value

    – ashish
    Nov 27 '18 at 9:11











  • You can check with debugger in javascript code for second click whether it is triggering $("li.clickable").click(function() or not.

    – Karan
    Nov 27 '18 at 9:14











  • I think the reason is because i have an update panel. How can i do this with update panel

    – ashish
    Nov 27 '18 at 9:15











  • You have to put hdnListId inside Updated panel

    – Karan
    Nov 27 '18 at 9:17











  • i tried that but that didnt work. I think the function is only getting executed once

    – ashish
    Nov 27 '18 at 10:33
















0














Add <asp:HiddenField ID="hdnListId" runat="server"></asp:HiddenField> in your html. Give clickable class to each li you want to save id.



Add following javascript.



$(function() {    
$("li.clickable").click(function() {
$('#' + '<%=hdnListId.ClientID%>').val(this.id);
});
});


On server side, You can simply get value from hdnListId.Value






share|improve this answer
























  • Hi Karan this works only for the first click but when i select second item from the list it doesnt show the value

    – ashish
    Nov 27 '18 at 9:11











  • You can check with debugger in javascript code for second click whether it is triggering $("li.clickable").click(function() or not.

    – Karan
    Nov 27 '18 at 9:14











  • I think the reason is because i have an update panel. How can i do this with update panel

    – ashish
    Nov 27 '18 at 9:15











  • You have to put hdnListId inside Updated panel

    – Karan
    Nov 27 '18 at 9:17











  • i tried that but that didnt work. I think the function is only getting executed once

    – ashish
    Nov 27 '18 at 10:33














0












0








0







Add <asp:HiddenField ID="hdnListId" runat="server"></asp:HiddenField> in your html. Give clickable class to each li you want to save id.



Add following javascript.



$(function() {    
$("li.clickable").click(function() {
$('#' + '<%=hdnListId.ClientID%>').val(this.id);
});
});


On server side, You can simply get value from hdnListId.Value






share|improve this answer













Add <asp:HiddenField ID="hdnListId" runat="server"></asp:HiddenField> in your html. Give clickable class to each li you want to save id.



Add following javascript.



$(function() {    
$("li.clickable").click(function() {
$('#' + '<%=hdnListId.ClientID%>').val(this.id);
});
});


On server side, You can simply get value from hdnListId.Value







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 27 '18 at 9:06









KaranKaran

3,3912424




3,3912424













  • Hi Karan this works only for the first click but when i select second item from the list it doesnt show the value

    – ashish
    Nov 27 '18 at 9:11











  • You can check with debugger in javascript code for second click whether it is triggering $("li.clickable").click(function() or not.

    – Karan
    Nov 27 '18 at 9:14











  • I think the reason is because i have an update panel. How can i do this with update panel

    – ashish
    Nov 27 '18 at 9:15











  • You have to put hdnListId inside Updated panel

    – Karan
    Nov 27 '18 at 9:17











  • i tried that but that didnt work. I think the function is only getting executed once

    – ashish
    Nov 27 '18 at 10:33



















  • Hi Karan this works only for the first click but when i select second item from the list it doesnt show the value

    – ashish
    Nov 27 '18 at 9:11











  • You can check with debugger in javascript code for second click whether it is triggering $("li.clickable").click(function() or not.

    – Karan
    Nov 27 '18 at 9:14











  • I think the reason is because i have an update panel. How can i do this with update panel

    – ashish
    Nov 27 '18 at 9:15











  • You have to put hdnListId inside Updated panel

    – Karan
    Nov 27 '18 at 9:17











  • i tried that but that didnt work. I think the function is only getting executed once

    – ashish
    Nov 27 '18 at 10:33

















Hi Karan this works only for the first click but when i select second item from the list it doesnt show the value

– ashish
Nov 27 '18 at 9:11





Hi Karan this works only for the first click but when i select second item from the list it doesnt show the value

– ashish
Nov 27 '18 at 9:11













You can check with debugger in javascript code for second click whether it is triggering $("li.clickable").click(function() or not.

– Karan
Nov 27 '18 at 9:14





You can check with debugger in javascript code for second click whether it is triggering $("li.clickable").click(function() or not.

– Karan
Nov 27 '18 at 9:14













I think the reason is because i have an update panel. How can i do this with update panel

– ashish
Nov 27 '18 at 9:15





I think the reason is because i have an update panel. How can i do this with update panel

– ashish
Nov 27 '18 at 9:15













You have to put hdnListId inside Updated panel

– Karan
Nov 27 '18 at 9:17





You have to put hdnListId inside Updated panel

– Karan
Nov 27 '18 at 9:17













i tried that but that didnt work. I think the function is only getting executed once

– ashish
Nov 27 '18 at 10:33





i tried that but that didnt work. I think the function is only getting executed once

– ashish
Nov 27 '18 at 10:33




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53495669%2fhow-to-get-the-text-that-has-been-selected-from-listitem-of-an-unordered-list-in%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

Calculate evaluation metrics using cross_val_predict sklearn

Insert data from modal to MySQL (multiple modal on website)