how to navigate pages in asp.net - asp.net

I have to navigate to another page in asp.net suppose I have two pages i.e. Default.aspx and Default2.aspx how do I navigate between them ?

You could use anchors in your aspx page:
Click to navigate to Default2.aspx
or make a redirect in your code behind:
Response.Redirect("~/Default2.aspx");

there are many ways, here are a few to get you started
go there
<asp:HyperLink runat="server" ID="lnk" Text="go there" NavigateURL="default2.aspx" />
<asp:LinkButton runat="server" ID="btn" Text="go there" OnClick="server_method_that_redirects" />

On your server side codebehind you may also consider using Server.Transfer(..) instead of Response.Redirect(..).
Response.Redirect sends an instruction to the browser to change the page while Server.Transfer does it directly on the server side. Browse the web for further information about the differences.

Related

ASP FileUpload control issue in Chrome browser

I have a legacy webpage with an asp:FileUpload control on it with an OnClick event. When uploading an .xsls spreadsheet with parentheses () in the file name, e.g., "somefile (2).xsls," using Chrome browser, the UploadButton_Click handler is not called. Instead, the web page redirects to the default page as if an error occurred.
However, a filename without parentheses works fine. (No issue with IE.)
I need help debugging this. Breakpoints in the click handler are not hitting in this scenario. Response.Write, etc., are not good either because the event does not get hit.
The code is pretty much this:
<asp:FileUpload id="FileUpload1" runat="server">
</asp:FileUpload>
<asp:Button id="UploadButton"
Text="Upload file"
OnClick="UploadButton_Click"
runat="server">
</asp:Button>

Using an asp.net button to launch html code

I want to use an asp.net button to launch an outlook window using the following html.
<a href="mailto:sample#website.com?subject=Insurance Text">
What do I need to do to file html code from my onClick event?
Try this
<asp:Button runat="server"
ID="btn"
OnClientClick="document.location = 'mailto:sample#website.com?subject=Insurance Text'; return false;"
Text="Mail" />
There are two approaches. If you want the standard button, you could use something like this:
<asp:Button ID="MailToButton"
Text="Send Email"
OnClientClick="javascript: navigate('mailto:blah#blah.com'); return false;"
runat="server" />
EDIT 2: Never mind about the UseSubmitBehavior property - I was incorrect. You'll just have to use return false;. Apparently ASP.NET does not render a regular non-submit button. How to disable postback on an asp Button
If you want an anchor tag, you can just use the NavigateUrl property of the Hyperlink tag:
<asp:HyperLink ID="MailToHyperlink"
Text="Send Email"
NavigateUrl="mailto:blah#blah.com"
runat="server" />
You cannot launch Outlook from the standard click event in the code behind, however. The code behind click event occurs on the server, not on the client's machine, so whatever you do it needs to happen on the client's machine either through standard HTML or through javascript.
Why an ASP.NET button?
Just use a simple HTML button.
They are plenty of example on the web. This one should work: using mailto button click event

AjaxControlToolkit CalendarExtender Control not working in my website

I' using the AjaxControlToolkit CalendarExtender in my web site but after uploading it does how show the calendar control. I have registered the control on the page itself. The page postback when I click the image on which I applied the control.
What can be the reason of this?
Check whether you added ToolkitscriptManager in your page, which is in AjaxToolkit
If you are using an ImageButton to show the calendar,
then use ajax control toolkit and put these controls
<asp:ToolkitScriptManager runat="server" />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:ImageButton ID="ImageButton1" runat="server"
ImageUrl="calIcon.jpg" />
<asp:CalendarExtender ID="CalendarExtender1" TargetControlID="TextBox1"
PopupButtonID="ImageButton1" runat="server">
</asp:CalendarExtender>
If you are still getting the page postback when clicking the ImageButton, you can add onClientClick='return false;' to the imageButton
<asp:ImageButton ID="ImageButton1" runat="server"
ImageUrl="calIcon.jpg"
OnClientClick="return false;" />
Drag and place Script manager at top of the ajax control or at top of the form.
As you said that ajax calender works fine on local but when you uploaded it it started creating problems following are the workarounds give them a try.
Check that whether you uploaded the ajax toolkit dll on the server or not.
secondly make sure that you uploaded updated web.config file.
let me know if its helpful otherwise i will try finding other workarounds

Using Response.Redirect with jQuery Thickbox

I'm using jQuery Thickbox to display an iframe (upload.aspx) that allows a user to upload a file. In the code behind for the upload.aspx I finish by sending:
Response.Redirect("blah.aspx");
The page I redirect to is dynamic based on the results of the upload process. When this redirect happens, it happens inside the Thickbox and not the parent window as I'd like it to. Here's the calling ASP.NET page (home.aspx):
Add New
And here's the submit button inside of the upload.aspx page:
<asp:Button ID="btnUpload" runat="server" Text="Upload"
OnClick="btnUpload_Click" OnClientClick="self.parent.tb_remove();" />
This is designed to close the modal window and send control to the code behind to perform the file upload, processing, etc.
Has anyone experienced this before? How would I go about sending a redirect on the parent window?
You cannot send a redirect to a parent frame.
Instead, you need to use Javascript.
You can write top.location = "whatever"; in Javascript in the <iframe>.
Here's what I ended up doing.
Added server tags to the body element of upload.aspx:
<body id="mBody" runat="server">
Removed the Response.Redirect, and attached some JavaScript to run on the next load.
HtmlGenericControl body = (HtmlGenericControl)Page.FindControl("mBody");
body.Attributes.Add("onload", "window.top.location.href='blah.aspx';");
And removed the client click from the button:
<asp:Button ID="btnUpload" runat="server" Text="Upload"
OnClick="btnUpload_Click" />

Adding 'onClientClick' javascript to an ASP.NET Login control

I've got to put a login page from a 3rd party website in an iframe on another website that I'm developing. I need to add some JavaScript to break out of the iframe when the user logs in, but I can't make the login button to execute the JavaScript and do the postback for the login - just one or the other.
Here's the code from the iframe'd login page that I'm triying to adapt:
<asp:LoginView ID="LoginView1" runat="server">
<AnonymousTemplate>
<asp:Login ID="Login1" runat="server" OnAuthenticate="Login1_Authenticate">
<LayoutTemplate>
<asp:Label ID="lblUsername" runat="server" AssociatedControlID="Username" Text="Email" />
<asp:TextBox ID="Username" runat="server" Text="myName" />
<asp:Label ID="lblPassword" runat="server" AssociatedControlID="Password" Text="Password" />
<asp:TextBox ID="Password" runat="server" Text="myPassword" />
<asp:ImageButton ID="btnLogin" runat="server" CommandName="Login" ImageUrl="~/Images/login-submit.gif" AlternateText="Login" OnClientClick="top.location.href = document.location.href; return true;" />
</LayoutTemplate>
</asp:Login>
</AnonymousTemplate>
<LoggedInTemplate>
You are currently logged in blurb..
</LoggedInTemplate>
Currently when the login button is clicked, the login page breaks out of the iframe, but then I have to click the button again to log the user in. Can anyone see what I'm doing wrong? Thanks.
top.location.href is setting the url of the browser to be a new url so you are never completing the action of the click.
What you could do is set the target of the form to be "_top"
something like
OnClientClick="document.getElementById('MYFORM_CLIENTID').target='_top';return true;"
Looking at your code I think that on the first click you are not logging in. You are just redirecting the parent window to your login page (the one which is displayed in the IFrame at first). That is why you need to click that button twice to log in - on the second time there is no redirect, as the parent window's URL does not change, so basically on the second time the top.location.href = document.location.href part does not yield any results and the login proceeds.
I think that the right course of action would be to authenticate first, then redirect, the opposite of how it looks currently. You can add a script on postback on that page, so that it checks if it's running in a frame and if so, it redirects the parent window to another page. Of course if you can modify the code... With the amount of detail that was provided I'm only able to tell what may be wrong and suggest a fix, but can't give a solution.

Resources