[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

ImageButton

Posted on 2009-02-17
19
Medium Priority
?
928 Views
Last Modified: 2013-11-26
I've got an image button that I added some javascript code to to print every page.  I added the imagebutton to my master page, because I want it to display on every page.  What's happening is somehow the control is ruining my login/membership functions, and a user can't login when this control is on the page.  Can anybody explain what is happening here?
0
Comment
Question by:JeffEae
  • 7
  • 5
  • 5
  • +1
19 Comments
 
LVL 12

Assisted Solution

by:techExtreme
techExtreme earned 100 total points
ID: 23660764
can you post the markup here? and if possible the part of code behind as well if control is used therein as well.
0
 
LVL 19

Accepted Solution

by:
daveamour earned 1800 total points
ID: 23660790
I think image buttons may automatically post/submit so try just using an image instead - doesn't have to be a button you can still use onclick.
0
 
LVL 11

Expert Comment

by:jmwheeler
ID: 23660803
Are your login/membership functions using javascript?  If so you probably have an error in the javascript for your image button.  Try removing all of the javascript for the image button and see what happens.  If your page works again, re-add the javascript for the image button one line at a time untl it breaks to determine which line is causing you a problem.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:JeffEae
ID: 23660913
Whoops, forgot to post the code.  
<asp:ImageButton ID="ImageButton1" runat = "server" ImageUrl="~/images/print_friendly.gif"/>
 
 
Thats in the master page.  And in the page_load of the master page, I do
 
  ImageButton1.Attributes.Add("onclientclick", "javascript:window.print()");  

Open in new window

0
 
LVL 11

Expert Comment

by:jmwheeler
ID: 23660953
Change "onclientclick" to "onclick"
0
 
LVL 11

Expert Comment

by:jmwheeler
ID: 23660967
OnClientClick is what .Net uses to fire javascript events because they overrode the OnClick event as a server-side event. In the end it still gets translated back to an onclick javascript event because that is the javascript specification.
0
 
LVL 11

Expert Comment

by:jmwheeler
ID: 23660980
Also, window.print() should do it, no need for the "javascript:" in front.
0
 

Author Comment

by:JeffEae
ID: 23661115
Hey jmwheeler, I just have this now

<asp:ImageButton ID="ImageButton1" runat = "server" ImageUrl="~/images/print_friendly.gif"/>

    protected void Page_Load(object sender, EventArgs e)
    {
        DateTime dt = DateTime.Now;
        Timelbl.Text = dt.DayOfWeek.ToString() + " , " + dt.ToString("m") + "  " + dt.ToString("t");

        ImageButton1.Attributes.Add("onclick", "window.print()");  
           
    }

This is all on my master page so its sort of a continuation of the last question I asked.  Now, the login page displays fine, but won't login and the window.print is being fired after the form doesn't login.  
0
 
LVL 12

Expert Comment

by:techExtreme
ID: 23661428
Hi, try replacing your imagebutton with the one shown here
and remove the one line of code you have added in master page's code behind to set javascript on image button.
<asp:ImageButton ID="ImageButton1" runat = "server" OnClientClick="window.print()"  ImageUrl="~/images/print_friendly.gif"/>



0
 

Author Comment

by:JeffEae
ID: 23661429
Now I've commented out the ImageButton1.Attributes.Add("onclick", "window.print()");  and the ImageButton messes up my forms authentication.  I'm guessing the answer relates to this:

http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/Q_24150371.html

But how to I give an ImageButton control authentication?
0
 

Author Comment

by:JeffEae
ID: 23661510
hey tech, just tried it, and it's firing up the window.print after the user fails to logon.  So its doing something to my forms authentication  too
0
 
LVL 12

Expert Comment

by:techExtreme
ID: 23661707
Hi, ensure these things firstly:

  • you would not need print button on login page, as it'll be useless there.
  • If the master page is same for login page, where you have print button, you need to create a different page for login where only login controls reside.
  • So , once you are logged in,  you should not get any error regarding print controls atleast.
0
 

Author Comment

by:JeffEae
ID: 23661847
Tech,

The ImageButton is part of my heading, that's why I put it below the banner, so I wouldn't have to worry about it in the other pages.  It's just a pic of an Icon that is shaped as a printer.  It looks best just by the heading, putting it on each individual page will end up placing it incorrectly in terms of margins
0
 
LVL 12

Expert Comment

by:techExtreme
ID: 23661938
You say its firing after the user fails to logon, I don't get it. You want to login and print stuff or ?
On which button press are you getting the error?
0
 

Author Comment

by:JeffEae
ID: 23661972
The print ImageButton/Icon is just set there so after the user logs in, he/she can print whatever he wants. If they want to print the login screen, they should be able to do it.  And yea, the markup you posted just executes after I click on the 'log in' button, and the login control doesn't work after that.  I'm not purposely putting in the wrong username/password, it just doesn't login anymore and after it doesn't login, the window.print gets executed.  
0
 
LVL 19

Expert Comment

by:daveamour
ID: 23661999
Can I draw your attention to my earlier post:
I think image buttons may automatically post/submit so try just using an image instead - doesn't have to be a button you can still use onclick.
0
 
LVL 12

Expert Comment

by:techExtreme
ID: 23662016
The markup I posted was for the print button and not for the login button. Actually if you have a codebehind handler for login button, you shouldn't write javascript on top of it, unless you want to prevent user from submitting the form say for example with empty username or something like that.
So the window.print should not execute when you press login button, as it is actually for the different button.
0
 
LVL 11

Assisted Solution

by:jmwheeler
jmwheeler earned 100 total points
ID: 23662041
Can you post all of you code, login button included?  That might help.

If you do decide to just make it an image instead of an imagebutton, you can use the style property (or css class) to still change the cursor as if it were a link.

ex.
<asp:Image ID="Image1" ImageURL="images/myimage.bmp" style="cursor:pointer;" runat="server" />
0
 

Author Closing Comment

by:JeffEae
ID: 31547832
Just used an image instead, I could have sworn I had tried that but I have it working now.  Thanks all, your help was really appreciated on this time-sensitive manner!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question