scroll go to the top page - asp.net

net use web methods to save data from JavaScript when i press save the all page go the top how i can save state position after post back

You can set it programmatically
Page.MaintainScrollPositionOnPostBack = true;
In the page declaration
<%# Page MaintainScrollPositionOnPostback="true" %>
Or in the web.configs <system.web> section.
<pages maintainScrollPositionOnPostBack="true" />

The reason the page is returning to the top, is because it is being Submitted and hence reloaded.
If you want to keep the position of the page you have 2 options;
1) Use a Anchor (See: http://www.hypergurl.com/anchors.html)
2) Post your form using AJAX and then you do not need to reload the page
Option 2 is the prefered, if you are using webforms you could use an AJAX Update Panel, or if you are using MVC you can do it using JQuery.

try to setting the following page directive in your page
<%# Page MaintainScrollPositionOnPostback="true" %>

I solved the question, and my method of doing this was the following:
I put a javascript:void(0) in an a tag, as shown here:
<a href="javascript:void(0)">

Related

How to work with update panel, if the page abc.aspx contains usercontrols?

I have a web page abc.aspx using this page like master page, in this page i wrote a Html tag iframe using this i frame as content place holder.
I'm calling home.aspx page in this iframe tag.
in my home.aspx page i have some user-control. So , My question is
how can i able to implement the update panel in this scenario please tell me the solution.
Thank You,
Gorus.
After commenting the xhtmlConformance tag in web.config, update panel working normally.
<system.web>
<xhtmlConformance mode="Legacy" />
</system.web>
please refer below link....
http://weblogs.asp.net/scottgu/archive/2006/12/10/gotcha-don-t-use-xhtmlconformance-mode-legacy-with-asp-net-ajax.aspx

How to change content of master page dynamically

I am developing a master page for an e-commerce website. I have Left-Side Menubar on the Master Page. This left menubar contains Category list and changes as user change categories. Categories are stored in SQL DB. So, I want to rebuild this menubar as category changes, Is it possible?
Have look on www.actgreen.com.au/www
And also I want to create Breadcrumb for website, how can I do.
I am using asp.net 4.0.
Thanks.
Well , we don't know what exact approach you are using in your code to bind left menu..Also you must be binding your left menu in your master page itself. So on each time you click on left menu you can rebind it again by providing some parameter to it.
or if you need to call it from some different page or from your content pages..then you can try it like this..
System.Reflection.MethodInfo mInfo = this.Page.Master.GetType().GetMethod("RefreshLeftMenu");
mInfo.Invoke(this.Page.Master, null);
I do it this way...hope its helpful for you too..
You can use controls on masterpage and change them on page OnLoad
Label MyLabelBrand = (Label)Master.FindControl("LabelBrand");
MyLabelBrand.Text = "Fabrikam";
If you want to call method Refresh() of Master page, you need call Master.Refresh();.
To do this you need register master type on ContentPage:
<%# Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %>
<%#MasterType VirtualPath="Site.Master" %>

maintain postback with WebForm_DoCallback

Does anyone know how to maintain postback while calling WebForm_DoCallback? it always set the vertical scrollbar of the page to the very top.
thanks
I Call this method in onclick event of html input button, instead of asp:Button. Sample:
input id="ButtonCallServer" type="button" onclick="MyServerCall(txtSum.Value)"
function MyServerCall(args) { WebForm_DoCallback('__Page', args, ClientCallbackFunction, "", null, false); }
on the page you want to maintain position set the following page level directive:
<%# Page Language="..." MaintainScrollPositionOnPostback="true" ... %>
If you wanted you could set this for the whole site, in which case add the following to your web.config under the system.web block:
<pages maintainScrollPositionOnPostBack="true" />
i had similar problem yesterday after {don't remember what changes}.
the MaintainScrollPositionOnPostback just stopped working.
use this:
string postbackInvokerUniqueID = Request.Forms["__EVENTTARGET"];
if (!string.IsNullOrEmpty(postbackInvokerUniqueID))
Page.FindControl(postbackInvokerUniqueID).Focus();
that may not give the the exact scroll position, but is close enough

Calendarextender is not displayed with masterpages

I'm working with masterpages and after reading a lot of answers I can't find why my calendarextender doesn't appear
Here is my code
http://pastebin.com/m789f935e
did you check the setting in the webconfig file . do you have all the required settings for ajax . ?
Have you tried changing the TagPrefix in the
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
directive to something other than asp? Not sure how well referencing more than one assembly for a single TagPrefix is supported.
The info here and here sort of backs me up...sort of. Give it a shot and let us know how it goes.
I see you have more than one ScriptManager tag... one in the Master page and one in your VerFavoritos.aspx page. I suggest you add one ScriptManager in the Master, place it right after the tag and before anything else in the Master page. Remove any ScriptManager tags from the VerFavoritos.aspx page.
Hope this helps.
Do you have the AJAX Control Toolkit .dll in your References?
The entry in the web.config you are looking for is something along this line:
<add assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagPrefix="AjaxControlToolkit"/>
When this happens you can use the calendar extender with syntax like:
<AjaxControlToolkit:CalendarExtender ... />
Rebor.
My application have a page that displays a ModalPopUp (the modal pop up pf ajax toolkit).
Inside the PopUp i put a calendarExtender, but the calendar appears behind the PopUp, so, to solve it i need to associate my Calendar to a CSS, like this:
<cc1:CalendarExtender ID="txtProximoContato_CalendarExtender" runat="server" PopupButtonID="imgCalendarProxContato"
Enabled="True" CssClass="CalendarPopup" TargetControlID="txtProximoContato">
</cc1:CalendarExtender>
and the CSS class
.CalendarPopup
{
z-index: 10500 !important;
}
I dont know if it is your problem, but i hope this help you
To be honest the Ajax Control Toolkit has been superceded by things like jQuery. Seriously consider using jQuery UI or extjs instead - I've always found this library to buggy and badly supported.
I copied/pasted your code almost exactly as it was and the calendar extender appeared.
Follow these steps exactly and it should work for you
Uninstall and reinstall AJAX 1.0.
From within VS 2005, create an "AJAX Enabled Website" instead of a regular website (VS 2008 automatically creates this type of website).
Add a reference to AjaxControlToolkit and it should work.
If you are still having trouble
Send me your solution. I'll correct it and send it back to you.

Form tag on ASP.net page

I have a web application that has a page that loads the content from the database. I want to be able to put a form in the dynamic content, but .net doesn't let the inside form perform it's action. Is there a way to allow this or some other way I can get a form on a dynamic content page?
--EDIT--
I think I need to clarify something. This is an aspx page that loads content from the database. As far as I know, the text I pull from the db and stick in the Label is never compiled or processed by the .net wp, thus I can't use the code behind to fix this issue.
This is a common problem, when you want to have a non-postback form to a 3rd party site (like a PayPal button, for example).
The problem occurs because HTML doesn't let you have form within a form, and most ASP.NET pages have a <form runat="server" /> "high up" in the HTML (or in the Master page).
My favorite solution is to hide the "high up" form tag, while still showing all of the content. Then you can feel free to dump any tags you want in the body. If you do this dynamically you can choose on a page-by-page basis which pages have custom forms.
I created a class called GhostForm.cs to handle this. You can read all about it here:
http://jerschneid.blogspot.com/2007/03/hide-form-tag-but-leave-content.html
There can only be one form on the page (the asp form); you have to use that form somehow.
To clarify, there can only be one form processed.
Not with webforms, no. You have to work within the one, full page form by using an event handler connected to a Button to LinkButton. Fortunately, it's pretty easy to do:
foo.aspx:
...
<asp:TextBox id="txtFoo" runat="server" />
<asp:Button id="btnFoo" runat="server" onclick="btnFoo_Click />
...
foo.aspx.cs:
...
protected void btnFoo_Click(object sender, EventArgs e)
{
string s = txtFoo.Text;
// do something with s
}
...
Dino Esposito has an article from MSDN magazine that covers handling multiple forms or "simulating" sub forms in ASP.Net that might just answer all your questions.
http://msdn.microsoft.com/en-us/magazine/cc164151.aspx
Any work around would be hacky and very ugly. By design asp.net uses a form tag to post and get data. This is why they call it a Web Forms Application. Html does not allow nested forms. What you want to do is use a WebRequest in your code behind.
If you are trying something like a paypal button you could simply use something like this.
Markup:
<div id="PayPalButtonContainer" runat="server"></div>
Code Behind:
public static string GetPayPalButtonMarkup()
{
const string markup = #"https://www.paypal.com/cgi-bin/webscr
?cmd=_xclick&business={0}
&item_name=Widget
&amount={1}
&currency_code=USD";
return markup;
}
PayPalButtonContainer.InnerHtml = string.format(GetPayPalButtonMarkup,"YOUR PAYPAL USER NAME", "YOUR PRICE VALUE");
you either have to deal with the postback by adding a server side click event handler to what you want to be the "sub forms" submit button (this is how web formas deals with multiple submit type buutons on the same page) or do soemthing clever with AJAX if you dont want a full post back
I've run across this issue before. One workaround that I have done is to place my code that I want my action to be done upon inside of an asp:Panel. With the panel you can set the attribute of "DefaultButton" to a button inside of the panel, and clicking the button (or pressing "enter") will fire that button's click event. I've found this quite handy when wanting to submit a "form" by pressing enter when I have a master page that contains the only allowable asp:Form.
Hope this helps.
When I first came across this problem, I found the simplest solution for me was to simple COPY and PASTE the Master page and give it a slightly different name, something like:
SiteNameMasterPage 'Default page with FORM tag
SiteNameMasterPageNF 'No Form tag
And then depending on wether I wanted a FORM tag or or not, simply change the masterpage link at the top of my CONTENT-PAGES, like this
<%# Page Title="" Language="VB" MasterPageFile="~/SiteName.master" %>
<%# MasterType VirtualPath="~/SiteName.master" %>
<!-- This masterpage has the default FORM tag -->
or
<%# Page Title="" Language="VB" MasterPageFile="~/SiteNameNF.master" %>
<%# MasterType VirtualPath="~/SiteNameNF.master" %>
<!-- This masterpage does NOT have the default FORM tag -->
and then in the content page, wherever I want to place my form I can include the <form> tag

Resources