Add javascript Function in MenuItem Click event
-
Dear All, I am new to ASP.Net with c#. I am working in Menu control. I am trying to place a javascript function in MenuItem click event. when MenuItem are clicked certain action should be taken based on javascript function. any ideas to implement it in c#.
Abdul Rahaman Hamidy Database Developer Kabul, Afghanistan
-
Dear All, I am new to ASP.Net with c#. I am working in Menu control. I am trying to place a javascript function in MenuItem click event. when MenuItem are clicked certain action should be taken based on javascript function. any ideas to implement it in c#.
Abdul Rahaman Hamidy Database Developer Kabul, Afghanistan
You don't need to implement it in C#, add an onclientclick to the menu item markup or do it from javaScript
I know the language. I've read a book. - _Madmatt
-
Dear All, I am new to ASP.Net with c#. I am working in Menu control. I am trying to place a javascript function in MenuItem click event. when MenuItem are clicked certain action should be taken based on javascript function. any ideas to implement it in c#.
Abdul Rahaman Hamidy Database Developer Kabul, Afghanistan
You can do this on server side, codebehind cs file:
foreach (MenuItem item in myMenu.Items)
{
item.NavigateUrl = "javascript:CallaMethodOfJavascript();";
} -
You can do this on server side, codebehind cs file:
foreach (MenuItem item in myMenu.Items)
{
item.NavigateUrl = "javascript:CallaMethodOfJavascript();";
}thx, I have used following to do it.
using (StringWriter sw = new StringWriter())
{
using (HtmlTextWriter htmlWriter = new HtmlTextWriter(sw))
{
using (HyperLink menuLink = new HyperLink())
{
menuLink.NavigateUrl = item.NavigateUrl;
menuLink.Text = item.Text;
if (isEndNode)
menuLink.Attributes["onclick"] = "return displayControlName('" + item.Text + "','" + item.Parent.Text + "');";
else
menuLink.Attributes["onclick"] = "return msgOnly();";
menuLink.RenderControl(htmlWriter);
item.Text = sw.ToString();
}
}
}Abdul Rahaman Hamidy Database Developer Kabul, Afghanistan
-
Dear All, I am new to ASP.Net with c#. I am working in Menu control. I am trying to place a javascript function in MenuItem click event. when MenuItem are clicked certain action should be taken based on javascript function. any ideas to implement it in c#.
Abdul Rahaman Hamidy Database Developer Kabul, Afghanistan
<a href=”somepage.htm?foo=32” onClick=”functionName('val')”>foo 32</a> or <input type="button" value="123" onclick="func('123')" /> "I am trying to place a javascript function in MenuItem click event. " or do you mean OnClientClick="func();" ? <asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="func();" /> http://mydevbank.com[^]