I have a hyperlink on my master page that directs me to the homepage.
It works on every page except a page that has validators.
How do I make the hyperlink work?
More information would be helpful, but I have a suggestion: make sure the hyperlink doesn't have a property called "CausesValidation" = True. A hyperlink control causes a post, which will trigger a validator. Turn it off and you should be good to go.
Related
I need some help on an issue, related with asp.net validators and postback.
The issue is that I have a page say 'p1' and it has a master page 'm1'. In addition to these I also have a usercontrol 'u1'.
Now, the issue is that on master page 'm1', I have a button that initiates a postback. And on my usercontrol 'u1', I have some fields which I need to check/validate and stop the postback if the fields are invalid.
I have tried using customvalidators and forcefully calling Page.Validate() method. But by doing this, I can see the page.IsValid property is false but sill the postback happens. I have even tried to write a return statement if the control fields are invalid but it doesn't helps..
Please note that I do not want to make any changes in the masterpage as this may have high impact on the other pages.
If clicking a button causes postbacks even when the page is invalid (as in your case it is proven with Page.IsValid property is False), then this means the button isn't configured to check for validations on the client side.
Solution 1:
You need to intialize the "CausesValidation" Property of the Button with the value True"
However, this requires changing the markup of the "Button" on the markup. And this isn't something you wish to perform.
Solution 2:
You can from within your page, access the Button of the Master page from within the Load Event and Initialize the CausesValidation property of the button to True.
Have a look at the following link to find the button from within the master page:
https://msdn.microsoft.com/en-us/library/xxwa0ff0.aspx
I am using using Response.Redirect to transfer control to another page. but this disables back navigation in the browser. What is alternative way to achieve this ?
Response.Redirect does not disable the back button by any means. Check it using web-console or put debug point on your page and check again. I think in your case the browser back button is working but your page may be forcing it to redirect again to the second page
You can do a client-side redirect.
Here is code for 5 different ways to do this with JavaScript
I recommend the first one which is to set the window.location.href property in JS.
You should use Server.Transfer() instead.
You must have added a javascript function somewhere in your project ( like MasterPage or parent page ) which is disabling back button and which is bad from user point of view , otherwise it isn't possible for browser's back button to get disabled on its own just because you have used response.redirect in your code -behind .
I have a web page that prompts for user input via DropDownLists in some table cells. When a selection is made the selection replaces the DropDownList so that the action can only be performed once. In the case that a change needs to be made I want to be able to click a button that reloads the page from scratch. I have Googled and Googled but I have not managed to find a way to do this.
Any advice is appreciated.
Regards.
Put a link on the page with the text "Reload" and the url the url of the page. It's perfectly valid to have a page with a link to itself.
If you don't like the link idea, use a standard Button and in the click event, use Response.Redirect to redirect to the current page.
You can set an OnClick for your button that resets each DropDownList's SelectedIndex to 0 instead of reloading the page from scratch. Alternatively, you can set a Response.Redirect([the page's url]) into the OnClick as is suggested here.
How do I setup a default setting so that if I do not set an OnClick (i.e the asp.net OnClick attribute) explicitly for an asp:LinkButton tag, it will not render an onclick(html attribute for javascript) attribute client side? By default, asp.net adds an onclick='doPostBack....' for the LinkButton.
Case for use:
There is a LinkButton tag on the page. For this page, if the user has one friend, I only want to run client side code if the button is clicked and would not for any reason want to make a post back. If the user has more than one friend I would want a click to trigger a postback.
Solutions that include the following are not helpful:
Using any asp.net Ajaxtoolkit
Dynamically switching the control type (i.e. if friends == 1 use a asp:Hyperlink)
-I want to avoid this because it is not scalable. There might be many cases where I want an asp:Link tag to do a postback or to not do a postback depending on the user context or user attributes
Using OnClientClick (I am using jQuery would like to avoid this)
Solution that would be helpful if possible:
If I could see server side at runtime whether an OnClick event was explicitly set on an asp:LinkButton tag, this would solve my problem, too. any ideas?
How about rather than dynamically switching the controls (as you mentioned is a solution you don't want), you could always use an asp:HyperLink and set the NavigateUrl property to redirect your page back to itself with a query string of some sort indicating what was clicked.
If you don't want the post to happen at all, simply leave the NavigateUrl property blank.
Of course, this will be pretty worthless if the rest of the page is dependent on ViewState and such.
http://forums.asp.net/t/1129106.aspx
This link explains how to see server side at runtime whether an OnClick event was explicitly set using reflection
From what I've already read this appears to be impossible, but I wanted to see if anyone out there has a secret trick up their sleeve or at least a definitive "no".
Supposedly a master page is really just a control for a content page to use, not actually the "master" of a content page. If I wanted to go from one content page, to another content page with the same master page, I would just say
Response.Redirect("PageB.aspx");
But this would immediately cause a postback, flickering the page, which is the crappy pre-ajax way of doing things.
In this current project, I'm trying to see if I could figure out how to change the current content page of a ContentPlaceHolder in the master page asynchronously, when a button is clicked on the master page.
Is this possible, if so how?
I don't know if you can between pages (.aspx) but it can definitely be done using UserControls.
ASP.Net pages each have their own URL so what you're trying to do is to go from one URL to another without any postback, that's just not how it's supposed to work.
Using user controls (.ascx):
Create a page that uses the MasterPage and use something like this in the content
<ajax:UpdatePanel ...>
<ContentTemplate>
<asp:PlaceHolder ...>
</ContentTemplate>
</ajax:UpdatePanel>
Search for UpdatePanel and tweak its settings to do what you want, then learn how to swap user controls in a placeholder.
No, you cannot because a master page is actually a control rendered on a particular aspx page, rather than actually containing the aspx page as it deceptively appears to be programmatically and in design view.
More Info:
You could however use a variety of other controls to simulate this effect. The asp:MultiView control is one example, each "page" could be made in a single view and placed in an update panel, thus allowing it to be switched asynchronously. Alternatively you could define each page in a separate user control and put those in an update panel, asynchronously switching the visible property on those controls as needed.
There are really a lot of different ways to achieve an effect similar to changing the master page's content placeholder.