admin管理员组文章数量:1405516
my client side code button1.Attributes.Add("onclick", "javascript:window.open('page1.aspx?CheckedItem=" + checkedItem.ToString() + "','mywindow',');"); is not executing on the first click.But it is working fine from second click onwards.I wrote this code inside the button click event.
I had tried to put this inside the page_load ,but the problem is i need to return a value from this page. here is the code
protected void btnPreview_Click(object sender, EventArgs e)
{
//StringBuilder checkedItem = new StringBuilder();
checkedItem.Length = 0;
foreach (ListItem i in chkValidation.Items)
{
if (i.Selected)
{
if (string.IsNullOrEmpty(Convert.ToString(checkedItem)))
{
checkedItem.AppendFormat(i.Text);
}
else
{
checkedItem.AppendFormat(",");
checkedItem.AppendFormat(i.Text);
}
}
btn_Preview.Attributes.Add("onclick",
"javascript:window.open('TimePhaseAttributePreview.aspx?CheckedItem=" +
checkedItem.ToString() + "','mywindow','menubar=0,resizable=0,width=350,height=250');");
}
Please help me
my client side code button1.Attributes.Add("onclick", "javascript:window.open('page1.aspx?CheckedItem=" + checkedItem.ToString() + "','mywindow',');"); is not executing on the first click.But it is working fine from second click onwards.I wrote this code inside the button click event.
I had tried to put this inside the page_load ,but the problem is i need to return a value from this page. here is the code
protected void btnPreview_Click(object sender, EventArgs e)
{
//StringBuilder checkedItem = new StringBuilder();
checkedItem.Length = 0;
foreach (ListItem i in chkValidation.Items)
{
if (i.Selected)
{
if (string.IsNullOrEmpty(Convert.ToString(checkedItem)))
{
checkedItem.AppendFormat(i.Text);
}
else
{
checkedItem.AppendFormat(",");
checkedItem.AppendFormat(i.Text);
}
}
btn_Preview.Attributes.Add("onclick",
"javascript:window.open('TimePhaseAttributePreview.aspx?CheckedItem=" +
checkedItem.ToString() + "','mywindow','menubar=0,resizable=0,width=350,height=250');");
}
Please help me
Share Improve this question edited Jan 3, 2012 at 8:40 albertjan 7,8276 gold badges46 silver badges77 bronze badges asked Jan 3, 2012 at 8:06 user1117040user1117040 1412 gold badges2 silver badges12 bronze badges 5-
Given your "I wrote this code inside the button click event" I will need to see the code! Got a jsfiddle? Also, don't put
javascript:
in the value of an onclick attribute. – Mr Lister Commented Jan 3, 2012 at 8:10 - hai MrLister,here is the code – user1117040 Commented Jan 3, 2012 at 8:11
- not related to the answer. above code you are adding attribute in a loop. it shoud be outside of the loop – Chamika Sandamal Commented Jan 3, 2012 at 9:26
- @MrLister why not putting javascript there? – draks ... Commented Oct 26, 2012 at 7:35
-
Because it's redundant.
onclick="dosomething()"
has the same result asonclick="javascript:dosomething()"
so you don't need thejavascript:
. The colon also makes it look (to the untrained eye) like a URL. – Mr Lister Commented Oct 26, 2012 at 9:16
2 Answers
Reset to default 0put the code in any page event. like page_load,init.. or use RegisterClientScriptBlock
You need to use OnClientClick, not OnCLick
Change your code to
button1.OnClientClick = "javascript:window.open('page1.aspx?CheckedItem=" + checkedItem.ToString() + "'
,'mywindow',')";
本文标签:
版权声明:本文标题:c# - button1.Attributes.Add("onclick", "javascript:window.open('page1.aspx?CheckedItem=&q 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744898108a2631185.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论