"Dealing with the postback problem on a single page website with an ASP

I'm encountering an issue on my One page website with different sections. The second section includes a grid view that allows inline editing.

Problem: Whenever the OnClick method is triggered, it causes a postback and the page automatically scrolls up to the first section.

To try and fix this, I attempted redirecting like so:

Response.Redirect("Home.aspx#section2");

Although this successfully redirects, it resets the gridview edit template back to the item template. It seems like the gridview gets rebound in this process.

I also experimented with a JavaScript solution from here, but encountered the same issue.

<asp:Button ID="Edit" runat="server" Text="Edit" OnClick="Edit_OnClick" 
 OnClientClick="document.location.href+='#section2';return false;"></asp:Button>

Furthermore, I tried using the postbackurl attribute of a link button, only to face the same unwanted outcome.

If you have any suggestions or ideas on how to tackle this problem effectively, please share your insights! I simply need to navigate to section 2 without the page refreshing or redirecting. Thank you for your assistance in advance! :)

Answer №1

To ensure smooth functionality, it is recommended to relocate your gridview within an update panel and trigger the update panel in the code-behind upon button click.

Here is how you can achieve this:

ASPX:

Set MaintainScrollPositionOnPostback attribute to true within the page tag for seamless scrolling during postbacks.

You can also opt for partial postbacks

<asp:UpdatePanel ID="updList" runat="server" UpdateMode="Conditional">
                                    <ContentTemplate>

.......

  </ContentTemplate>
                                </asp:UpdatePanel>

Code Behind:

protected void Edit_OnClick(object sender, EventArgs e)
        {
           //code to update data or save data
            updList.Update();           
        }

Answer №2

Discover more about UseSubmitProperty or experiment with this...

<a data-toggle="modal" href="login.aspx#myModal">Forgot Password?</a>

as well as

<div aria-hidden="true" aria-labelledby="myModalLabel" role="dialog" tabindex="-1" id="myModal" class="modal fade">
                        <div class="modal-dialog">
                            <div class="modal-content">
                                <div class="modal-header">
                                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                                    <h4 class="modal-title">Forgot Password ?</h4>
                                </div>
                                <div class="modal-body">
                                    <p>Enter your e-mail address below to reset your password.</p>
                                    <asp:TextBox ID="emailForgot" placeholder="Email" CssClass="form-control" runat="server" TextMode="Email"></asp:TextBox>
                                </div>
                                <div class="modal-footer">
                                    <button data-dismiss="modal" class="btn btn-default" type="button">Cancel</button>
                                    <asp:LinkButton ID="LinkButton1" CssClass="btn btn-theme" runat="server" OnClick="LinkButton1_Click">Submit</asp:LinkButton>
                                </div>
                            </div>
                        </div>
                    </div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How to dynamically alter a PHP variable using a JavaScript button click on the existing webpage

I've spent the last hour scouring stackoverflow for answers to my problem, but trying out solutions has only resulted in errors - perhaps because I'm attempting to implement it on the same page. I've experimented with saving the value to a ...

Develop a NuGet package from a RESTful Web API Application

My ASP.NET CORE 2.0 REST API web service is comprised of several projects (layers), but due to external constraints, it cannot function as intended. It was suggested that I create a nuget package for this WEB API. While I have never created a nuget packag ...

Partial implementation of jQuery datepicker feature facing technical issues

Greetings, I have a functional datepicker implemented in my code as follows: <link rel="stylesheet" href="uidatepicker/themes/blitzer/jquery.ui.all.css"> <script src="uidatepicker/jquery-1.5.1.js"></script> <script src="uidate ...

Is there a way to gather information from a web service and neatly display it within an HTML table?

Is it possible to fetch a JSON array from a web service and save it in a variable? Consider the following table structure: <table id="myTable" border="1"></table> The table is populated using the code below: // JSON array var myData = metho ...

Combining each function in Google Sheets script with the && operator allows for setting a range of values to compare against the array

Looking for help with a coding issue involving checking data format before running specific code. I've successfully implemented checks to prevent sending duplicate or empty data, but now I'm struggling with validating that the data is in the cor ...

When the only source is available, the image undergoes a transformation

Is there a way to dynamically adjust the height of an image using JQuery or JavaScript, but only when the image source is not empty? Currently, I have an image element with a fixed height, and even when there is no source for it, Chrome still reserves sp ...

Ways to optimize memory usage and eliminate Vue reactivity

I've encountered an issue where Vue's observer and reactive components are using up a significant amount of memory during runtime. You can see an example of this in the Memory allocation on DevTools. Is there a way to detach observables and preve ...

Is it possible to utilize the identical key pair for both StrongNaming an assembly and digitally signing a file?

Utilizing a public/private key pair, I aim to sign an assembly and configuration settings received by the assembly via USB key. The reasoning behind this approach is to allow the assembly to verify its own integrity and also validate the settings file upo ...

Transferring JSON information from JavaScript to PHP

I have searched for various solutions, but have not found one yet. I am stuck with the following piece of code and my suspicion is that the jsondata arriving at the PHP script is empty. Unfortunately, I am clueless on how to debug this issue as the script ...

Executing ValidateCredentials returns a false result (even with the correct username and password), triggering Event 4625 on the domain server

I have encountered a puzzling issue while calling PrincipalContext.ValidateCredentials within the domain context, resulting in a false negative without any clear reason. using (PrincipalContext pc = new PrincipalContext(ContextType.Domain, "DOMAINNAME")) ...

AngularJS encounters failure during shared data service initialization

As a newcomer to AngularJS, I aim to develop an application in adherence to John Papa's AngularJS style guide. To familiarize myself with these best practices, I have opted for the HotTowel skeleton. My application requires consuming an HTTP API endp ...

What is the best way to change the class of an input using jQuery when it is not empty?

Utilizing Bootstrap 4. I am working on a feature where I have four text inputs. If any of these inputs contain values, I want to add a specific class to a button. Upon clicking the button, my goal is to clear all input values and remove the aforementione ...

Struggling to utilize Mechanize with Python for choosing options from a dropdown menu on an ASP.NET website

Trying to scrape product information from an ASP.NET page (found at ) using Mechanize in Python. The page contains a dropdown menu with various food brands. Here is a snippet of the HTML code: <fieldset class="pulldownfieldset"> <label>. ...

Steps to store a string with all characters in a JavaScript variable

I am faced with a situation where I need to pass variables that are considered Javascript objects, in a format similar to the following: var pageVars= [ { origin:'page', property:'name', value:'whatever' }, { origin:& ...

Creating a visually appealing gantt chart in React Native using the react-google-charts library - here's how!

These are the current packages I am using: react-google-charts 1.5.5 react 16.0.0-beta.5 react-native https://github.com/expo/react-native/archive/sdk-22.0.1.tar.gz I am currently working on rendering a Gantt Chart and you can find an example here and a ...

What crucial element am I overlooking in the React Transition Group Component while implementing it for a carousel design?

I'm trying to add a feature to my Carousel where the opacity changes between images. When clicking on the icons, the images should transition smoothly. I've been using React Transition Group, but for some reason, it's not working as expected ...

Storing pictures in MongoDB as binary large objects using React

I have been working on utilizing the dropzone-react component for uploading images. Upon successful upload, it provides me with the blob:http://test address which allows me to view the uploaded image. However, I am facing a challenge in saving this image a ...

The onsubmit event in Javascript activates the parent's onclick event

On my HTML page, I have a table with a form in each row. Clicking on the row should open a detail page, but clicking within the form should not trigger this action. Here is an example of what my row looks like: <tr onclick="window.parent.location.href ...

Why is my website appearing on Google with the URL as the name?

After uploading my HTML, CSS and JavaScript website online (without the use of any frameworks or libraries like React or Next), I noticed that when I searched for it on Google, the URL showed up as the website name instead (see image here). Following the ...

Leveraging AJAX for database variable checks and PHP and JavaScript to redirect to specific pages based on the results

I am currently exploring the use of AJAX to validate variables in a database. The goal is to redirect to a specific page if the validation is successful. However, during this testing phase, I am not actually checking any variables. My focus is on verifying ...