c# - ASP, Listview conditional Alert -
c# - ASP, Listview conditional Alert -
i'm working listview in want htmltablecell possess onclick property driven codebehind rather javascript.. i'm guessing that's pretty much dream getting obey c# code... anyways want run:
protected void show_anm(object sender, eventargs e) { label hiddenc = (label)listview1.findcontrol("hidden"); alert.show(hiddenc.text); }
and here's alert class
public static class alert { public static void show(string message) { string cleanmessage = message.replace("'", "\\'"); string script = "<script type=\"text/javascript\">alert('" + cleanmessage + "');</script>"; page page = httpcontext.current.currenthandler page; if (page != null && !page.clientscript.isclientscriptblockregistered("alert")) { page.clientscript.registerclientscriptblock(typeof(alert), "alert", script); } } }
the point creating listview 2 conditional tablecells, 1 appears when status met , other appears every other time (that's alredy sorted out). 1 demanding status clickable, , upon clicking it'll display alertbox info specific db cell... sorry if language , question seemes off, english language isn't native language , haven't doused myself in coffe yet. help on matter appritiated edit1*
<asp:listview ................ <itemtemplate> <tr ......> <td id=default .....> <asp:label ........ text='<%# eval("stuff") %> /> </td> <td id=conditional onclick=alert()..........> <asp:label ......... text='<%# eval("stuff") %> /> </td> <td id=hidden visible=false ...........> <asp:label ......... text='<%#eval("stuff want in alert") %>' /> .....
<script tyupe="text/javascript"> function alert() { var msg = document.getelementbyid("tried label id , tablecell id nil seemingly worked").value; alert(msg); } </script>
i made workaround shows info want display in labels tooltip i'd still prefer alertbox work feels more natural click something.
edit2 in case wondering used itemdatabound event bind visibility of cells default , conditional within if clause create sure command exists , conditions met.
i confused why you're doing you're doing. why want codebehind handle onclick event of htmltablecell when pumping out javascript show alert anyway?
why not handle whole logic within javascript?
a postback htmltablcell require javascript
set tablecell phone call javascript function obtain alert text hidden value , display that;
function showalert() { var message = document.getelementbyid("hidden").value; alert.show(message); }
c# javascript asp.net listview
Comments
Post a Comment