how to get the text that has been selected from listitem of an unordered list in content page in asp.net
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
|
show 10 more comments
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
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 likeSideNavMenu
. Then you just need to cast theMaster
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 adde.stopPropagation();
and adde
as parameter in click invoke function.. read more aboute.stopPropagation();
HERE
– Curiousdev
Nov 28 '18 at 7:02
|
show 10 more comments
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
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
c# asp.net
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 likeSideNavMenu
. Then you just need to cast theMaster
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 adde.stopPropagation();
and adde
as parameter in click invoke function.. read more aboute.stopPropagation();
HERE
– Curiousdev
Nov 28 '18 at 7:02
|
show 10 more comments
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 likeSideNavMenu
. Then you just need to cast theMaster
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 adde.stopPropagation();
and adde
as parameter in click invoke function.. read more aboute.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
|
show 10 more comments
1 Answer
1
active
oldest
votes
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
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 withdebugger
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 puthdnListId
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
|
show 1 more comment
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
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 withdebugger
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 puthdnListId
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
|
show 1 more comment
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
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 withdebugger
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 puthdnListId
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
|
show 1 more comment
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
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
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 withdebugger
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 puthdnListId
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
|
show 1 more comment
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 withdebugger
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 puthdnListId
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
|
show 1 more comment
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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 theMaster
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 adde
as parameter in click invoke function.. read more aboute.stopPropagation();
HERE– Curiousdev
Nov 28 '18 at 7:02