|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Postback in Web ControlsI have a encapsulated a Datagrid control and text boxes etc to make a
customized datagrid control. I have a "search" button on the page. If the user clicks on Search or even if the "Search " button is the currently selected button and the user presses "Enter" key the postback occurs and the control is rebound, but if the user simply enters text in the search criteria and hits the "Enter" key, the postback event is not thrown and the control loses it's data. I want to prevent this from happening. Thank you, Wizzy There are 2 options; both using Javascript by trapping the event OnKeyPress
when the Enter key is pressed during typing in the TextBox: 1- event.returnValue=false; which basically disables the effect of pressing the Enter key 2- Trigger the submit button click event You may view the code for demo# 9 from my samples: http://www.societopia.net/samples/ Show quoteHide quote "Wizzy" wrote: > I have a encapsulated a Datagrid control and text boxes etc to make a > customized datagrid control. > > I have a "search" button on the page. If the user clicks on Search or even > if the "Search " button is the currently selected button and the user presses > "Enter" key the postback occurs and the control is rebound, but if the user > simply enters text in the search criteria and hits the "Enter" key, the > postback event is not thrown and the control loses it's data. > > I want to prevent this from happening. > > Thank you, > > Wizzy > Hi Phillip,
Thanks for your reply. This should take care of the first situation. I also have a series of radio button controls with AutoPostBack set to true. Again the application works fine, but if I click an already selected radio button (or click on a selected radio button) the same thing happens . Thanks in Advance, Wizzy Show quoteHide quote "Phillip Williams" wrote: > There are 2 options; both using Javascript by trapping the event OnKeyPress > when the Enter key is pressed during typing in the TextBox: > 1- event.returnValue=false; which basically disables the effect of pressing > the Enter key > 2- Trigger the submit button click event > > You may view the code for demo# 9 from my samples: > http://www.societopia.net/samples/ > -- > HTH, > Phillip Williams > http://www.societopia.net > http://www.webswapp.com > > > "Wizzy" wrote: > > > I have a encapsulated a Datagrid control and text boxes etc to make a > > customized datagrid control. > > > > I have a "search" button on the page. If the user clicks on Search or even > > if the "Search " button is the currently selected button and the user presses > > "Enter" key the postback occurs and the control is rebound, but if the user > > simply enters text in the search criteria and hits the "Enter" key, the > > postback event is not thrown and the control loses it's data. > > > > I want to prevent this from happening. > > > > Thank you, > > > > Wizzy > > You are welcome.
Regarding your question on the RadioButtonList... ASP.NET creates an onClick event for the AutoPostBack=true setting on the RadioButton and the RadioButtonList, which means that a RadioButton will fire up on every click regardless of the change in status (checked/unchecked). To achieve the effect that you want, I would replace the RadioButtonList with individual RadioButtons that are wired to the same event handling method, e.g. <asp:RadioButton AutoPostBack=True ID="Radiobutton1" Runat="server" Text="value1" OnCheckedChanged ="Radiobutton_CheckedChanged"></asp:RadioButton> <asp:RadioButton AutoPostBack=True ID="Radiobutton2" Runat="server" Text="value2" OnCheckedChanged ="Radiobutton_CheckedChanged"></asp:RadioButton> <asp:RadioButton AutoPostBack=True ID="Radiobutton3" Runat="server" Text="value2" OnCheckedChanged ="Radiobutton_CheckedChanged"></asp:RadioButton> And in the codebehind: protected void Radiobutton_CheckedChanged(object sender, System.EventArgs e) { //disable the autopostback for the selected radio button RadioButton rb = (RadioButton)sender; rb.AutoPostBack =false; //uncheck the other radio buttons } Show quoteHide quote "Wizzy" wrote: > Hi Phillip, > > Thanks for your reply. This should take care of the first situation. > > I also have a series of radio button controls with AutoPostBack set to true. > Again the application works fine, but if I click an already selected radio > button (or click on a selected radio button) the same thing happens . > > Thanks in Advance, > > Wizzy > > "Phillip Williams" wrote: > > > There are 2 options; both using Javascript by trapping the event OnKeyPress > > when the Enter key is pressed during typing in the TextBox: > > 1- event.returnValue=false; which basically disables the effect of pressing > > the Enter key > > 2- Trigger the submit button click event > > > > You may view the code for demo# 9 from my samples: > > http://www.societopia.net/samples/ > > -- > > HTH, > > Phillip Williams > > http://www.societopia.net > > http://www.webswapp.com > > > > > > "Wizzy" wrote: > > > > > I have a encapsulated a Datagrid control and text boxes etc to make a > > > customized datagrid control. > > > > > > I have a "search" button on the page. If the user clicks on Search or even > > > if the "Search " button is the currently selected button and the user presses > > > "Enter" key the postback occurs and the control is rebound, but if the user > > > simply enters text in the search criteria and hits the "Enter" key, the > > > postback event is not thrown and the control loses it's data. > > > > > > I want to prevent this from happening. > > > > > > Thank you, > > > > > > Wizzy > > >
Finding a way to bind ASP.NET controls(two way) to a typed-dataset
Error in DataList test query - aspnet 2.0 getting Membership userid to use and store in a custom database Gridview Updates not writing to database after clicking update Datagrid paging I lose my sort Dynamically Adding DataLists Coloring Calendar !!! FormView DataBinding in Insert mode Hyperlink Control Status text |
|||||||||||||||||||||||