Is it possible to place a button on top of an Image control in a custom control ?
You can take Image button
like this
<asp:ImageButton runat="server" ID="imgButton" ImageUrl="~/images/asc.gif" />
set your image url , this image button work same as normal asp button,
You can also get server side Click event of this button.
Related
Is it possible to put a button on my user control .ascx (the web part in this case), and have a customized image with that? What I am trying to do is have a "print" button to print the page.
However, I don't want to use the default asp button, I want to have a the special "print" icon associated with it. So, can I do this and still use <asp:button>?
Or is it just better to make that "print" icon a link, and do OnClick on the link event?
You can use link button as suggested.
But in my opinion you should not use any server-side control if you don't have to use it on server side.
What you can do create an image tag <img src.... and use onclick event on this image.
When you create a server side controls it is added to your view state key value pair of information. Which is an overhead.
or you can use like this
<a href="javascript:window.print()">
<img src="print.gif">
</a>
or even
<img src="print.gif" name="pic" onclick="javascript:window.print()"/>
You could try the ImageButton class, then you can have a printer icon for example.
Try this:
<asp:ImageButton ID="submitButton" runat="server" OnClick="submitButton_Click" ImageUrl="~/images/printer.jpg" />
I'm using the OnTextChange event on a textbox on an ASP.NET page. To have this working I have to put 'AutoPostBack=true'.
The problem is that the textbox is on the bottom of the page, and when the text changes it has to fill another textbox. This is working fine but when the event triggers the page refreshes and jumps to the top of the page, so I always have to scroll down again to see it. (Due to the autopostback)
Is there anything I can do to prevent it to jump to the top of the page?
Use UpdatePanel and put that text box for which u r triggering OnTextChange event in of from ajax extensions and dont forget to include scriptmanager at top of the page
the code goes like this
<asp:UpdatePanel>
<content>
<asp:TextBox runat="server" AutoPostBack="true" OnTextChanged="textbox_textchanged">
</asp:TextBox>
</content>
</asp:UpdatePanel>
In the page_load event write below code.
this.MaintainScrollPositionOnPostBack = true;
Earlier, I had a button control on my web page. but now I changed it to a CSS button suting my needs. Before this, the button control was performing code-behind operation but now I switched to this CSS button.
Delete profile
How can I accomplish the same code-behind process now?
You can change the anchor to be a server side control (turning it to a HtmlAnchor control) and use the ServerClick event:
Delete profile
To keep it simple, you could use a linkbutton and get the server side click event
<asp:LinkButton ID="lb1" runat="server" onclick="lb1_Click" CssClass="cssClass" />
how to opacity the asp.net page on button click , till procees get complete of respective button.
Can anyone help me ?
If it's a regular postback, use client side javascript to disable the button before the actual postback happens.
<asp:Button runat="server" ID="myBtn" OnClick="YourServerSidePostBack"
OnClientClick="document.getElementById('<%= myBtn.ClientID %>').disabled = true;" />
I have a webpage where there are two buttons and a textbox. When the page loads and user presses enter, the first button is clicked - and that is ok.
I would like to assure that if user enters the textBox and types anything there and THEN presses enter, the second button is clicked.
When I enter the textBox I can tell that the first button will be used when I press enter, because it is a bit dark-blue-bordered then.
I tried javascript's
if (event && event.keyCode == 13)
document.getElementById("Button2").click();
but it somehow doesn't work. So my second thought was that there must be a possibility to tell the browser which button should defaultly react for an enter press when I'm in a specific textBox (the dark-blue-bordered button).
Edit: it might matter that first button is input and the second one is asp:Button
Edit2: Page.Form.DefaultButton is not an option, as there are somehow two default buttons. One should be clicked if user doesn't enter a textBox, other one if he is inside the textBox. Changing DefaultButton is not an option as this would require a postback after entering textBox by a user...
The Page.Form.DefaultButton allows to set which button will react to the Enter key.
<asp:Panel runat="server" DefaultButton="Button2" >
<asp:TextBox runat="server" />
<asp:Button ID="Button2" runat="server" Text="Button2" OnClientClick="alert('Button2')"/>
</asp:Panel>
As soon as you start using the textbox - button2 will be the default button. Up until then the other button will be the default
DefaultButton property