From: Andy O'Neill on

"Mr. Arnold" <Arnold(a)Arnold.com> wrote in message
news:%232IoaKV0KHA.4412(a)TK2MSFTNGP02.phx.gbl...
> JohnE wrote:
>> Hello. I have an asp:Button that in the click event I would like to have
>> it run a javascript function (function ProteusListPrint()). I currently
>> have the following in the click event;
>>
>> btnProteusListPrint.Attributes.Add("onclick", "ProteusListPrint()");
>>
>> This is not working. Am I missing something or is this not the correct
>> way to reference it in the click event of the button (C#)?
>>
>> Thanks... John
>>
>>
>
> You have server side onclick. And you have client side onclick that works
> on the client side where you can access javascript on the client side.
>
> Are you using the right onclick?

By definition, yes he is.

From: Alexey Smirnov on
On Apr 1, 11:47 am, "Andy O'Neill" <aon14nocannedm...(a)lycos.co.uk>
wrote:
> "Alexey Smirnov" <alexey.smir...(a)gmail.com> wrote in message
>
> news:c6d6bbe7-0e5b-4a57-aa98-a27d079d5061(a)33g2000yqj.googlegroups.com...
>
> >Your code looks correct. You need to check if ProteusListPrint() is
> >working properly. Try to add, for example,
>
> I concur.
> The problem is that the javascript isn't working for whatever reason.
>
> That "Attributes.Add"  injects javascript which will run on the client.

I got your point, I see now that he said "in the click event of the
button (C#)". Not sure what does it exactly mean, but for sure the
code has to be in the Page_Load event as it is already mentioned by
Andrew.
From: JohnE on


"Alexey Smirnov" wrote:

> On Apr 1, 11:47 am, "Andy O'Neill" <aon14nocannedm...(a)lycos.co.uk>
> wrote:
> > "Alexey Smirnov" <alexey.smir...(a)gmail.com> wrote in message
> >
> > news:c6d6bbe7-0e5b-4a57-aa98-a27d079d5061(a)33g2000yqj.googlegroups.com...
> >
> > >Your code looks correct. You need to check if ProteusListPrint() is
> > >working properly. Try to add, for example,
> >
> > I concur.
> > The problem is that the javascript isn't working for whatever reason.
> >
> > That "Attributes.Add" injects javascript which will run on the client.
>
> I got your point, I see now that he said "in the click event of the
> button (C#)". Not sure what does it exactly mean, but for sure the
> code has to be in the Page_Load event as it is already mentioned by
> Andrew.
> .
>

I should have been a bit clearer plus provide further information. Below is
the source code for the button, the full function, and the code behind.

<asp:Button ID="btnProteusListPrint" runat="server" Height="25px"
Width="100px" Text="Print" onclick="btnProteusListPrint_Click" />

function ProteusListPrint()
{
var a = window.open('ProteusListPrint.aspx', '',
'height=500px,width=800px,scrollbars=1');
a.document.close();
a.focus();
a.print();
}


protected void btnProteusListPrint_Click(object sender, EventArgs e)
{
btnProteusListPrint.Attributes.Add("onclick", "ProteusListPrint()");

}


I have found that if I use an html input button and add the function to the
button's onclick in the source code, it works fine. But, if I use an
asp:button it does not. So, if I understand what is being provided, what I
have in the code behind click event should actually go in the page_load?
Then what goes in the click event for when the user clicks on the button on
the webpage?

I am rather new to asp.net/c#/javascript/html so please excuse my newbieness
type questions.

.... John






From: Andrew Morton on
JohnE wrote:
> I should have been a bit clearer plus provide further information.
> Below is the source code for the button, the full function, and the
> code behind.
>
> <asp:Button ID="btnProteusListPrint" runat="server" Height="25px"
> Width="100px" Text="Print" onclick="btnProteusListPrint_Click" />

Change
onclick="btnProteusListPrint_Click"

to
onClientClick="ProteusListPrint()"


And remove this code:

> protected void btnProteusListPrint_Click(object sender, EventArgs
> e) {
> btnProteusListPrint.Attributes.Add("onclick",
> "ProteusListPrint()");
>
> }

HTH,

Andrew


From: JohnE on


"Alexey Smirnov" wrote:

> On Apr 1, 11:47 am, "Andy O'Neill" <aon14nocannedm...(a)lycos.co.uk>
> wrote:
> > "Alexey Smirnov" <alexey.smir...(a)gmail.com> wrote in message
> >
> > news:c6d6bbe7-0e5b-4a57-aa98-a27d079d5061(a)33g2000yqj.googlegroups.com...
> >
> > >Your code looks correct. You need to check if ProteusListPrint() is
> > >working properly. Try to add, for example,
> >
> > I concur.
> > The problem is that the javascript isn't working for whatever reason.
> >
> > That "Attributes.Add" injects javascript which will run on the client.
>
> I got your point, I see now that he said "in the click event of the
> button (C#)". Not sure what does it exactly mean, but for sure the
> code has to be in the Page_Load event as it is already mentioned by
> Andrew.
> .
>

I might have gotten it figured out. I added the button click event to the
page_load as it was mentioned. In the button click I removed it leaving the
button click event empty. Now it is working as intended when the print
button is clicked.

If this is correct, great. If not, let me know.

Thanks to everyone for their feedback.