Disable all controls and links on redirection - asp.net

I need information and code. What I want to achieve is that when user click on a link or control, the rest of the controls and links will become disabled. So user can't click on any link or control while page is redirecting.

Place the controls withing a div, and on redirection, change the CSS of the div.
If you wish to do the same from code behind then please use
<div ID="DivID" runat="server"/>
and then you can access the same from code behind.

You can put a panel and inside of it put all the controls and disable it when you redirect:
<asp:Panel ID="Pan1" runat="server" >
...
</asp:Panel >
And before redirect disable it:
Pan1.Enable = False

Related

Set Default Button Enter - Master Page

Hi everybody i have the next problem. I have to set a button as default when i press Enter. I can use DefaultButton in the Form because now all my pages inherits from Master Page and i have a Content from the Master Page and this isn't work. Somebody could give me any alternative to solve this please. Thanks
According to Enter Key - Default Submit Button:
ASP.NET 2.0 introduces a wonderful work around for this. By simply
specifying the "defaultbutton" property to the ID of the ,
whose event you want to fire, your job is done.
The defaultbutton property can be specified at the Form level in the
form tag as well as at panel level in the definition tag.
The form level setting is overridden when specified at the panel
level, for those controls that are inside the panel.
Also, the Event Handler for the specified button, fires thereby
simulating a true submit button functionality.
Like this
<form id="form1" runat="server" defaultbutton="Button1">
<div>
<asp:Button ID="Button1" runat="server" Text="Button1" OnClick="Button1_Click" />
</div>
Or you can achieve this by
Page.Form.DefaultButton = crtlLoginUserLogin.FindControl("LoginButton").UniqueID
or just
Page.Form.DefaultButton = LoginButton.UniqueID
This will work.
One way is through to recursively search through all your child pages controls and find the first button, get the id and set the default button of your form.
Although I have never tried this, I dont think its a very good idea as it is slow and error prone.
An alternative may be to do it through javascript/jquery, see this answer:
Submit form with Enter key without submit button?

ASP.NET Login control focus in FireFox

I am using the Login control. Just in FireFox, I am finding that I cannot click directly on the UserName field. I need to tab through all the other elements on that page. Just wondering if there is a work around to this issue?
<asp:Login ID="LoginUser" runat="server" EnableViewState="false" RenderOuterTable="false" OnLoggedIn="LoginUser_LoggedIn">
You can do this by adding the following code to the Page_Load method on your login page:
AppLogin.Focus();
this.Form.DefaultButton = "ctl00$BodyPlaceHolder$AppLogin$LoginButton";
This will also cause the "login" button to be clicked when you click enter.
Note: The full "path" (ctl100$BodyPlaceHolder...) may vary slightly depending on whether or not you're using master pages, panels, etc. You can simply view the element on the page in your favorite inspector and find the rendered name for the login button.
More details can be found at my blog here.

Link to Anchor tag with .net dropdownlist

im working on a website thats built using .net.
Theres a dropdown on my page that when an option is selected ther page refreshes, what I need though is for the page to refresh and link to an anchor further down my page "#company-detail"
<asp:DropDownList ID="DDL_Companies" runat="server" CssClass="selectd" onselectedindexchanged="DDL_Companies_SelectedIndexChanged" AutoPostBack="true">
<asp:ListItem>Select a partner...</asp:ListItem>
<asp:ListItem>opt</asp:ListItem>
<asp:ListItem>opt</asp:ListItem>
<asp:ListItem>opt</asp:ListItem>
<asp:ListItem>opt</asp:ListItem>
<asp:ListItem>opt</asp:ListItem>
</asp:DropDownList>
You can solve this with javascript instead of roundtrip to the server.
remove the AutoPostBack=true then add an onchange() event to the rendered select element. Do your navigation to the url there
EDIT:
Sorry, didn't see your requirement for the page to refresh. I guess you can, on the roundtrip to the server, add a RegisterClientScriptBlock so that the navigation the page section happens on the client side after the refresh. This will preserve the values on the page, instead of a response.redirect server side
http://msdn.microsoft.com/en-us/library/bahh2fef.aspx
You can reload page when select an item like this: Response.Redirect("yourHost.aspx#company-detail")

HTML buttons: Code-behind operation

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" />

Trying to self contain pop ups which use the AjaxToolkit ModalPopUpExtender

I have 3 different kinds of ajax popups that need to exist across my site. I was hoping that I could simply create a user control for each one and place the panel and modal popup extender inside each one but this doesn't seem to be working. Has anyone tried this before or do you have a recommendation as to how I can avoid duplicate code for each pop up on different pages? Thanks!
Ah I figured out my issue with the User Control I believe.
The ModalPopUpExtender requires the TargetID property to be set otherwise an error occurs. Since this is sitting in a UserControl I just created a dummy link button that doesn't do anything and I set the property visible to false.
<asp:LinkButton ID="lnkBlank" runat="server" Visible="false" />
<asp:Panel ID="plContainer" style="display: none;" runat="server">
Hello?
</asp:Panel>
<cc1:ModalPopupExtender ID="mpe" runat="server"
BehaviorID="test"
TargetControlID="lnkBlank"
PopupControlID="plContainer" />
Apparently it doesn't appreciate that and the moment I set the visible property to true it started working. Not sure what the reasoning is for a TargetID since, I would think, most pop ups could be called from multiple links about the page. Perhaps I'm still not entirely clear on how this control is supposed to be used.
One option would be to write the popups in a asp.net user control (a .ascx page) and include that on the pages you need the popups. Have a public method in the ascx page that will show the popup, and call it from the parent page when you need to. If you already have a script manager on the parent page, you can't have a second one in the ascx page, but other then that there shouldn't be anything that would stop this from working. Hope this helps!
edit: here's what my modal popup extender control looks like...
<cc1:ModalPopupExtender
ID="mpeClassroom"
BackgroundCssCLass="modalBackground"
runat="server"
CancelControlID="lbClose"
OnOkScript="onOk()"
TargetControlID="Button1"
PopupControlID="pnlClassroom">
</cc1:ModalPopupExtender>
in my code behind page, my method just calls mpeClassroom.Show();
The problem with hidden link as TrgetControlID is that; when u set its visibility as false, server doesn't render it as well. PopExtender then cannot find control on the page.
Instead of setting its visibility to false, try to apply a style with display:none. This should work !

Resources