Using Custom WebControl As DefaultButton For Panel?
Jan 25, 2010
I have created a custom web control to act as a button with an image. I would like to be able to set this as the target of the DefaultButton parameter of an ASP.NET Panel control. I have implemented the IButton interface, and no error is generated when loading the page using the control. However, when I press enter in a textbox within that panel, the Click event of the control is not raised. When I replace my control with a standard ASP.NET button, everything works fine.I have a test page with a panel containing a textbox, an instance of my custom button, and a standard asp.net button. The buttons are wired to an event handler which will change the textbox to the ID of the caller.When DefaultButton of the panel is set to the ASP.NET button, hitting enter in the next box works correctly - the page posts back, and the text box is populated with the name of the standard button. When DefaultButton of the panel is set to my button, hitting enter in the textbox causes the page to postback, but the Click event is not fired. Clicking the button manually works correctly.Does anyone know what I have to add to my custom control to make it handle the event coming from the Panel control? I'm looking using Reflector at the source code for Button, but cannot identify what is enabling this behaviour.I have posted the source of the control below, and the relevant source of the test page.Control Source:
public class NewButton : WebControl, IPostBackEventHandler, IButtonControl
{
public NewButton() : base(HtmlTextWriterTag.A) { }
[code]...
View 2 Replies
Similar Messages:
Aug 9, 2010
On my page i have a set of control containing parts of a form, like textboxes, checkboxes etc. I use those parts to build controls that I use in pages. For example:
UserAddToList.ascx
<asp:Panel ID="Panel1" runat="server" >
<sikt:PartFormTextboxLine runat="server" ID="samAccountName" />
<sikt:PartFormTextBoxLine runat="server" ID="name" />
<sikt:PartFormButtonLine runat="server" ID="addButton" UseSubmitBehavior="true" />
</asp:Panel>
PartFormButtonLine ascx:
<div>
<asp:Button ID="Button" runat="server" onclick="Button_Click" />
</div>
What I then want to do is to set the behavior of Panel1 to have a default button in the addbutton control. I have tried setting the Panel 1 default button to the botton in formbutonline like this: Panel1.DefaultButton = addButton.Button.UniqueID; in Page_load, but that does not work because .net throws this error: The DefaultButton of 'Panel1' must be the ID of a control of type IButtonControl. Now the button is public, so that should be ok. I have also tried ID and ClientID, with te same results. I have also tried to implement the IbuttonControl in PartFormButtonLine and map the implemented functions to the button
functions, which, as expected did not work. (Panel1.DefaultButton = addButton.ID) The problem as far as I can tell is that I cant seem to set the
"onkeypress="javascript:return WebForm_FireDefaultButton(event, 'MainContent_UserAddToList_addButton')"
of the container div to the correct value, onkeypress="javascript:return WebForm_FireDefaultButton(event, 'MainContent_UserAddToList_addButton_Button')" Everything else works, this is the last thing that needs to be fixed.. Idealy i want to fix this in the PartFormButtonLine file, as that would be better for reuse {update: removed quite abit of clutter in the ascx snippets}
View 5 Replies
May 18, 2010
I have a page where a user can type a From & To address, which brings up a new window w/ directions. In order to bring up the page in a new window, I'm using an HTML Button (not a Button Control).
The problem I'm having is when a user hits the enter key. I tried setting the default button for the pane, but quickly learned this isn't allowed.
I added some Javascript to capture when the enter key is hit, but this isn't working right on Firefox & the iPhone Mobile Safari browser.Is there a standard way to make an HTML Button the default button of a panel?
Ideally, I could use a Button Control, prevent it from going to the server & only execute the javascript. Is this possible?
View 1 Replies
Aug 11, 2010
UserAddToList.ascx
<asp:Panel ID="Panel1" runat="server" >
<sikt:PartFormTextboxLine runat="server" ID="samAccountName" />
sikt:PartFormTextBoxLine runat="server" ID="name" />
<sikt:PartFormButtonLine runat="server" ID="addButton" UseSubmitBehavior="true" />
</asp:Panel>
PartFormButtonLine ascx:
<div>
<asp:Button ID="Button" runat="server" onclick="Button_Click" />
</div>
I wish to set the default button of the panel to the button in PartFormButtonLine.
This is tested:
Findcontrol
Button bt = (Button)addButton.FindControl("Button");
Panel1.DefaultButton = bt.ClientID;
(also tested Panel1.DefaultButton = bt.ID; Panel1.DefaultButton = bt.UniqueID;)
Making a field: Panel1.DefaultButton = addButton.Button.ID;
(also tested Panel1.DefaultButton = addButton.Button.ClientID; Panel1.DefaultButton = addButton.Button.UniqueID;)
Setting the default button directly on addbutton. I tried both in aspx and in code to set the defaultbutton to the custom control and implement the IButton interface, but that was also fruitless.
View 2 Replies
Feb 15, 2010
I have a GridView control on a page with a Panel that has a DefaultButton. I am trying to get the "Update" button to work with the Enter key when a user edits a row. It works fine with the mouse. When I click on "Update", the row reverts back to View mode and the updated value is shown.
When the GridView is in the Panel, the Panel's default button (which submits the page) fires when I press Enter, before the RowCommand is even handled, and the update is lost.
When the GridView is not in the Panel, some other seemingly random button in the Panel fires, but not the "Update" button in my row's EditItemTemplate. Specifically, there is a CalendarExtender on the page, and the extender's popup button fires. Totally not what I want.
How can I get this to behave correctly?
Here is the structure of my mark-up code:
<asp:Panel ID="Panel1" runat="server" DefaultButton="btnSubmit">
<!--Form with controls-->
<asp:ImageButton ID="btnWSPODateCal" runat="server" />
<!--this button fires when I press enter while editing a grid row:-->
<ajaxToolkit:CalendarExtender ID="CalendarExtender1" runat="server"
TargetControlID="tbPODate" PopupButtonID="btnWSPODateCal" />
<!--more controls-->
<div class="button_row">
<asp:ImageButton ID="btnCancel" runat="server" />
<asp:ImageButton ID="btnSubmit" OnClick="btnSubmit_Click" />
</div>
</asp:Panel>
<asp:GridView runat="server">
<Columns>
<asp:TemplateField>
<EditItemTemplate>
<asp:ImageButton CommandName="MyUpdate"
ID="btnSubmitRow" runat="server"
CommandArgument="<%# ((GridViewRow) Container).DataItemIndex %>" />
View 2 Replies
Mar 16, 2010
I have a panel, with several textboxes and an ImageButton inside of it. One of the textboxes has a MaskedEditExtender and a MaskedEditValidator associated with it. When I hit enter from any other textbox besides the one with the MaskedEditValidator the defaultbutton that is defined in the Panel's DefaultButton property handles the enter key.However, when I am in the textbox with the MaskedEditValidator, the first button on the form is receiving the enter key. Now, if I take the MaskedEditExtender off of the page, and just leave the MaskedEditExtender, everything behaves as it should.Can anyone offer any insight into how I may get this to work properly, or is this a known bug?I tried searching the forums and found a similar post, but no conclusion was ever reached.
View 3 Replies
Jul 14, 2010
I have a search panel in my master page, which seems to be getting called when typing in another panel and hitting enter, even though the panel has a different defaultButton. The weird thing is the second and third panels work well, which ever one I put at the top calls the search button.
My search panel in my master page
<asp:Panel runat="server" ID="pnlSearch" DefaultButton="btnSearch">
<asp:TextBox ID="txtSearch" CssClass="fld" runat="server" Width="160" Text="Search..."
onclick="this.value='';" CausesValidation="false"></asp:TextBox>
<asp:ImageButton ID="btnSearch" ImageUrl="~/Images/search_arrow.gif" runat="server"
[Code]....
View 1 Replies
Dec 16, 2010
I'm creating a custom ASP.Net GridView and I want to be able to alter the __EVENTARGUMENT value but I can't figure out how to capture the returned value on the server side.
I'm creating the ability to have a collapsible representation, so the first level is the standard GridView and I will insert additional rows via JavaScript if they expand the first level row.
My problem is how to create a link on the selecond level rows that posts back with custom data.
View 2 Replies
Feb 18, 2010
How insert a drop list property into a custom webcontrol? This a drop list property is show all textbox control on usercontrol or webpage.
View 3 Replies
Nov 16, 2010
I built a webcontrol showing a complex user interface with a lot of javascript. Basically my webcontrol is similar to : [URL]
Now that most the user interface is working properly, I'm stuck with the following issue: I want to add a button (html button tag) which has to trigger an event. I have been able to declare the event, the event args, the delegate,etc. The page using my control may assign a handler and that handler is called correctly when I explicitely call OnServerControlClick (The name I gave to the event). I cannot make the link between the button in the user interface and the event in the webcontrol source code. When the button is clicked, I get an error message saying a dangerous Request.Form value has been detected.
View 3 Replies
Nov 29, 2010
I am creating a custom control by inheriting a server control, say LinkButton. There are properties like "BorderColor" available in LinkButton. Let's say, I don't want this particular property to be available when I create an instance of the custom control.
I want to completely hide this particular property (I don't want to override it but disable it.)
My code is as follows:
[Code]....
View 3 Replies
Apr 4, 2011
I am using ASP.NET Panel to set Default Button for some Controls like TextBox but it seems to not work due to AJAX Control Toolkit's AutoCompleteExtender.
Code is as below:
<asp:Panel ID="pnlSearchBox" runat="server" class="search-main-box" DefaultButton="lnkSearch">
<asp:TextBox ID="txtLocation" runat="server" CssClass="input-field" MaxLength="200" style="width: 182px; margin-bottom: 7px;"></asp:TextBox>
<ajaxToolkit:AutoCompleteExtender runat="server" BehaviorID="AutoCompleteEx" ID="aceLocation"
[Code].....
View 1 Replies
Mar 23, 2010
I have a page which holds a custom webcontrol and a usercontrol. I need to reference of webcontrol in usercontrol class. So, I make the declaration of webcontrol as public in page class. But, when I do "this.Page.", I don't see the webcontrol listed in list provided by intellisense. Most probably, I am missing something.
In an asp.net page, how to get a reference of a custom webcontrol from a usercontrol?
View 3 Replies
Mar 24, 2010
I have a page which holds a custom webcontrol and a usercontrol. I need to reference of webcontrol in usercontrol class. So, I make the declaration of webcontrol as public in page class. But, when I do "this.Page.", I don't see the webcontrol listed in list provided by intellisense. Most probably, I am missing something.
In an asp.net page, how to get a reference of a custom webcontrol from a usercontrol?
View 4 Replies
Jan 18, 2011
I created this simple custom web control:
[Code]....
I used this control on my page:
[Code]....
The problem is that when page is displayed in web browser is see default back color, font and border, values from page are not applied on the my control. Why?
View 1 Replies
Feb 23, 2010
I am writing a custom composite WebControl and want to expose styles of child controls it encapsulates to the ASP.NET designer. The code I currently have is similar to the skeleton below (which for simplicity only has one child control).
With the code below, I can see property "ChildPanelStyle" in the designer, but when I try to modify one of the properties (e.g. CssClass) in the designer, it immediately resets itself to its default value. It looks like the designer serialization isn't happening.
What am I doing wrong?
UPDATE
I've updated the sample with an additional style property that is managed directly by the custom control, rather than simply being the property of a child control.
The HeaderStyle property is persisted properly by the designer, but the ChildPanelStyle property isn't.
Of course I could manage all my styles like HeaderStyle, and apply them during rendering, but I'm hoping there's a simpler solution whereby child controls can take care of themselves, and I don't need any custom rendering.
[code]....
View 1 Replies
Apr 6, 2010
For test purposes I have created a simple button control that extends CompositeControl. I am able to place it on the page with a <asp:Content... and the Click event Bubbles without problem from the Control.
Now, here is the problem I am facing Due to design requirement I need to read the assembly and the classname from a table and dynamically create the control and add it to the <asp:Content. And when I do that the click event will not fire! Where am I going wrong.
Here is the code in the ButtonControl.cs
namespace Reports.Web.ServerControls {
[DefaultProperty("Text")]
[ToolboxData("<{0}:ButtonControl runat=server></{0}:ButtonControl>")]
public class ButtonControl : CompositeControl {
protected override void CreateChildControls() {
Button btn = new Button();
[Code]....
View 3 Replies
Dec 31, 2010
I have a Custom Server Control with a Collapsible Panel Extender. I want to be able to keep the Collapsable state (open or closed) when doing a Post Back.
Here is my Custom Control's ASP code:
[Code]....
View 1 Replies
Aug 5, 2010
I have a createuserwizard where people input their information. When I hit enter after typing in the data in the form it returns me to the homepage. How do I set the default button for the createuserwizard so that it goes to the next step rather then back to my homepage.
I'm not sure if it has to do with the fact that I have a defaultbutton set in a form in the masterpage and that defaultbutton overides the other pages defualtbutton....
View 3 Replies
May 18, 2010
I have a search textbox and a search submit button on my page. I have used the following code to allow the keyboard "Return" button to effectively "click" the search submit button without the user having a reach for their mouse.
[Code]....
However, I would like to hide the search button, since it clutters the page a little, and everyone is likely to run the search by pressing the Return key anyway. But the search ceases to run when the button is set to Visible="false", even if Enabled="true"!!Is there any way to hide the button whilst still allowing the search to work?
View 3 Replies
Jun 2, 2010
I have created my login controls on Master Page inside a LoginViewControl. Now i am having problems to declare
my Login Button as DefaultButton! I need this in scenario when people press Enter key for submiting insted of clicking on Login Button:
My Code on my Master Page looks something like this:
<form
id="MainForm"
runat="server">
<div>
[Code].....
View 5 Replies
Sep 8, 2010
I'm trying to implement a custom panel control that would act as a naming container. So far here is so what I've done.
First this is my custom control, MyPanel...
[ToolboxData("<{0}:MyPanel runat=server></{0}:MyPanel>")]
public class MyPanel: Panel, INamingContainer
{
}
And I try using it like so:
<cc1:MyPanel ID="A" runat="server">
<asp:HyperLink ID="TestHyperLink" runat="server" />
</cc1:MyPanel>
<cc1:MyPanel ID="B" runat="server">
<asp:HyperLink ID="TestHyperLink" runat="server" />
</cc1:MyPanel>
Obviously it doesn't work, that would have been too easy. ASP.net still complains about there being 2 DocumentHyperLink:
The ID 'DocumentHyperLink' is already used by another control.
View 1 Replies
Aug 12, 2010
I have a text box and many buttons. When user is in some text box and presses the "enter" key then specific button click event is raised. I read on the internet that there are some problems with the "enter" key and I tried few solutions but still it always enters that button event (that button is the first button in the page).
I tried creating a button which does nothing and writing this in the page_load:
idTextBoxFA.Attributes.Add("onkeydown","if(event.which || event.keyCode){if ((event.which == 13) || (event.keyCode == 13)) {document.getElementBtId('" + noEnterButton.UniqueID + "').click();return false;}} else {return true}; ");
All my page controls are in a form and I tried giving the form "defaultButton" property to that button I created. That didnt work either.
View 1 Replies
Jul 7, 2010
to have back fired on me a bit (See http://www.vbforums.com/showthread.php?t=620703). I have some other buttons on the page that I attach javascript to, e.g.:
btnPick12.Attributes.Add("onClick", "return Pick12();")
And in the page Head I have the script
Code:
<script type="text/javascript">
function Pick12() {
var PopupWindow = null;
[code]....
Basically I use javascript to pop open a window with a datepicker which they use to populate a textbox on the main page with a date. However, if I set a defaultbutton, when i click one of these buttons the popup window flashes to the front of the screen and then the main browser window gets focus over it. Without default button the popup stays on top.
View 4 Replies
Jan 31, 2011
I have several text boxes in an asp:Panel. When the user hits Enter from any of those boxes, I want the form to submit as if they've clicked btnAddTag. (When the cursor is not in those boxes, I have a different default submit button.)
The aspx:
<asp:Panel id="thePanel" runat="server">
<asp:Button ID="btnAddTag" Text="Add Tag" runat="server" />
</asp:Panel>
The vb:
tagPanel.DefaultButton = btnAddTag.UniqueID
The exception:
The DefaultButton of 'tagPanel' must be the ID of a control of type IButtonControl.
The value of btnAddTag.UniqueID is ctl00$phMain$btnAddTag (there's a master page, this section is called phMain).
I've also tried CType(tagPanel.FindControl("btnAddTag"), Button).UniqueID.
View 3 Replies