jteixeira Posted April 26, 2007 Share Posted April 26, 2007 Somebody can explain me why this dosen't workI'm workin in visual web developer 2005 in c# Button1.Attributes.Add("onclick", "Label1.Visible = false;"); Link to comment Share on other sites More sharing options...
aspnetguy Posted April 26, 2007 Share Posted April 26, 2007 The attributes refer to javascript events. You could to this Button1.Attributes.Add("onclick", "document.getElementById('Label1').style.display='none';"); Link to comment Share on other sites More sharing options...
jteixeira Posted April 26, 2007 Author Share Posted April 26, 2007 it dosen't work, the label are visible Link to comment Share on other sites More sharing options...
aspnetguy Posted April 26, 2007 Share Posted April 26, 2007 You setup the onclick attribute. When you click Button1 the label should disappear. Does this happen? Do you get any javascript errors?Please post the full code for this page and explain exactly what you want to happen Link to comment Share on other sites More sharing options...
jteixeira Posted April 26, 2007 Author Share Posted April 26, 2007 protected void Page_Load(object sender, EventArgs e) { //Imprimir página web corrent Button1.Attributes.Add("onclick", "document.getElementById('Label1').style.display='none';"); Button1.Attributes.Add("onclick", "window.print();"); if (Profile.i == "4") { Label1.Visible = true; Button1.Visible = true; Button2.Visible = true; } else { Label1.Visible = false; Button1.Visible = false; Button2.Visible = false; } if (Profile.i == "1" || Profile.i == "2" || Profile.i == "3" || Profile.i == "5" || Profile.i == "6") { Button3.Visible = true; } }protected void Button1_Click(object sender, EventArgs e) { } when i click in the button the label1 dont' dissappear Link to comment Share on other sites More sharing options...
aspnetguy Posted April 26, 2007 Share Posted April 26, 2007 you have set the onclick for Button1 twice. This is causing a conflict. Change these 2 lines Button1.Attributes.Add("onclick", "document.getElementById('Label1').style.display='none';"); Button1.Attributes.Add("onclick", "window.print();"); into Button1.Attributes.Add("onclick","document.getElementById('Label1').style.display='none';window.print();"); Link to comment Share on other sites More sharing options...
jteixeira Posted April 26, 2007 Author Share Posted April 26, 2007 there is no errors but the label1 is visible Link to comment Share on other sites More sharing options...
aspnetguy Posted April 26, 2007 Share Posted April 26, 2007 okay I think I know what is happening. The print dialog is coming up though, right?try this instead Button1.Attributes.Add("onclick","document.getElementById('Label1').style.display='none';window.print();return false;"); Without the return false; the PostBack gets fired resetting the label to visible. Link to comment Share on other sites More sharing options...
jteixeira Posted April 26, 2007 Author Share Posted April 26, 2007 it works Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.