Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8261855
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T03:33:31+00:00 2026-06-08T03:33:31+00:00

I’ve got a search page which shows a gridview. Items in the gridview are

  • 0

I’ve got a search page which shows a gridview. Items in the gridview are hyperlinks which create url string back to the same page – index.aspx

I’ve got index.asp checking for the presence of query string and deals with it just fine.

The problem i’ve got is when the user wants to enter a new search which is a form-submit. However the post back still includes the previous url query string – so that part of my code handles the request not the search.

Looking around I discovered PostBackURL:

  <asp:Button ID="btn_Search" runat="server" Text="Search" Cssclass="form_btn" OnClick="btn_Search_Click" PostBackUrl="index.aspx" />&nbsp;

In testing this did the trick. Form is submitted to index.aspx not to say index.aspx?Var1=1&Var2=2

When I publish to the live site however, this doesn’t work. I still get posted back with the url string.

The code outputted by asp for both the button and the javascript code are identical.

I’m fairly new to asp but i’m puzzled that the behaviour is different when running debug in VS2010 and running live on a webserver.

—

Ok some further investigation. I’m running Cassini but.. there are two buttons on my form – one is a search the other clear.

Both buttons generate the same sort of html:

<input type="submit" name="ctl00$MainContent$btn_Search" value="Search" onclick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;ctl00$MainContent$btn_Search&quot;, &quot;&quot;, false, &quot;&quot;, &quot;Index.aspx&quot;, false, false))" id="MainContent_btn_Search" class="form_btn" />

<input type="submit" name="ctl00$MainContent$btn_Clear" value="Clear" onclick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;ctl00$MainContent$btn_Clear&quot;, &quot;&quot;, false, &quot;&quot;, &quot;Index.aspx&quot;, false, false))" id="MainContent_btn_Clear" class="form_btn" />

The only difference in the above is the name, value, and the function they will call at the server – btn_clear or btn_Search.

The clear button works with the postbackurl on the live site; search button doesn’t.

Also, once a page has been served, is it not up to the page then to determine where it posts data next ? So if the page says i’m going here, that’s where it goes. My clear button says goto index.aspx with no url query string, and it works.

This puzzles me – if the clear button didn’t work on the live site I would think it’s either something to do with cassini or that in development it’s one pc vs live has pc & server. Also how can this be a cassini/IIS issue if it’s the browser that issues the command on where to go next ?

If I want to look at this further, I may need to use wireshark or similar to look at what actually leaves my browser window when I press search or clear.


Ok test project done. I’ve verified that this code works as I want it in debug. I can’t test the live deploy to IIS until Monday.

page1 aspx file:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="page1.aspx.cs" Inherits="page1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:GridView ID="gridview1" runat="server" AutoGenerateColumns="False">
    <Columns>
    <asp:HyperLinkField DataNavigateUrlFields="intVal" 
            DataNavigateUrlFormatString="page1.aspx?Var={0}" DataTextField="intVal" 
            HeaderText="URL String" />
    </Columns>
</asp:GridView>
<br />
<br />
Search &nbsp;<asp:TextBox runat="server" ID="searchtext"></asp:TextBox><br />

<asp:Button ID="btn_Search" runat="server" Text="Search" OnClick="btn_Search_Click" PostBackUrl="page1.aspx" />&nbsp;
<asp:Button ID="btn_Clear" runat="server" Text="Clear" OnClick="btn_Clear_Click" PostBackUrl="page1.aspx" /><br />
Result:<br /><br />
<asp:Label runat="server" ID="result">Initial Load</asp:Label>

</form>
</body>
</html>

page 1aspx.cs file:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class page1 : System.Web.UI.Page
{

public class MyItem 
{
    public int intVal {get; set;}
    public string stringVal {get; set;}
}

List<MyItem> ListMyItem = new List<MyItem>();

protected void Page_Load(object sender, EventArgs e)
{
    BuildList();


    result.Text = "Page Load: " + Request.Url;
}

protected void BuildList()
{
    MyItem MI = new MyItem();
    MI.intVal = 1;
    MI.stringVal = "111";

    ListMyItem.Add(MI);

    MI = new MyItem();
    MI.intVal = 2;
    MI.stringVal = "222";

    ListMyItem.Add(MI);

    gridview1.DataSource = ListMyItem;
    gridview1.DataBind();

}

protected void btn_Clear_Click(object sender, EventArgs e)
{
    result.Text = "Clear, URL: " + Request.Url + " Search= " + searchtext.Text;
}
protected void btn_Search_Click(object sender, EventArgs e)
{
    result.Text = "Search, URL: " + Request.Url + " Search= " + searchtext.Text;
}
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T03:33:34+00:00Added an answer on June 8, 2026 at 3:33 am

    Its one or the other
    Remove OnClick="btn_Search_Click" if you dont need to do anything in your code behind
    or remove PostBackUrl="index.aspx" if you dont want to be redirected

    you could ofcourse also use OnClick="btn_Search_Click" and then in code behind do a redirect to index.aspx

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I've got a string that has curly quotes in it. I'd like to replace
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
i got an object with contents of html markup in it, for example: string
I want to count how many characters a certain string has in PHP, but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.