javascript - I need to execute Java script function from c# code behind -
i need execute java script function c# code behind . using asp.net server control repeater , checking condition when condition true need run java script function turn hyper link display block javascript function
function myfunction(username) { document.getelementbyid("hyp").style.display = "block"; }
this asp.net code after condition if true call c# code behind method writetext() :
<%# eval("part2").tostring() == "part2" ? writetext(eval("albumtitle").tostring(), eval("albumtitle").tostring(), inc.tostring()) : writelink(eval("albumtitle").tostring(), eval("albumtitle").tostring())%> protected string writetext(string pagedataid, string albumid, string a) { clientscript.registerstartupscript(this.gettype(), "hwa", "myfunction('checkjj');", true); string html = ""; html += ""; return html; }
this c# call javascript function display html anchor block display none @ start
here anchor tag
<a id="hyp" name="hyp" href="#" class="lightbox<%=inc+"b" %>">part ii</a>
with html: <a id="hyp" name="hyp" ...
add attribute runat="server"
. on server side can access object if server control.
there not need execute javascript on server side perform action need.
something on "itemdatabound" event repeater:
void myrepeater_itemdatabound(object sender, repeateritemeventargs e) { string somevar = "somevalue" ; ((htmlanchor)e.item.findcontrol("hyp")).attributes.add ("css", "lightbox" + somevar); }
in order use event don't forget add event , runat server attribute :
<asp:repeater id="myrepeater" runat="server" onitemdatabound="myrepeater_itemdatabound"> <a id="hyp" name="hyp" href="#" runat="server">part ii</a> </asp:repeater>
you can find blog helpful:
Comments
Post a Comment