Intelligencia UrlRewriter PostBack Problem - c#

i am using Intelligencia UrlRewriter for converting my page
www.mywebsite.com/subject.aspx?subject=sub1
to
www.mywebsite.com/subjects/sub1.aspx
On this page, I have next and previos buttons to browse the different subcategories on that subject and have used DataList with paging to support that.
When the page is first shown(IsPostBack=False) it works fine, but when next button is fired, the URL converts into this:
www.mywebsite.com/subjects/subject.aspx?subject=sub1
Is there any idea why it is happening ?
My web.Config file is as follows :
Mt web hosting company uses IIS 7.
EDIT: I have windows 7 and I tried by using local IIS and it ran fine there.

You can code this in your master page for this problem
Here form1 is the form tag and place it in master page's load event
protected void Page_Load(object sender, EventArgs e)
{
form1.Action = Request.RawUrl;
}

Related

How to change view in asp.net?

Im wondering how i can change "views" with a button click in Visual Studio (asp.net)?
I have 2 .aspx files, one called Default.aspx and another one called Library.aspx. How can i make a button change the views to display the other aspx file?
I tried googling but didnt find anything useful. Any help here is appreciated. Thanks
Ok, assuming default.aspx is in desing mode, then just drop a button from the toolbox onto the web page.
Say, like this:
Now, double click on the button, and we are jumped to code behind.
protected void Button1_Click(object sender, EventArgs e)
{
Response.Redirect("Library.aspx");
}
So, we put for the code to jump to the web page Library.aspx
We get this then:
And now, when I click on that button, I am jumped to the web page called Library.aspx - we should see this (assuming the web page Library.aspx exists).

aspx pages not working after adding application in IIS

i have webapplication. In my master page i have few link buttons which are as below
<asp:LinkButton ID="link1" runat="server" OnClick="linkAge_Click">Age</asp:LinkButton>
<asp:LinkButton ID="link2" runat="server" OnClick="linkName_Click">Name</asp:LinkButton>
In my Visual studio i have seperate folder called Age and Name and under those there are default.aspx.
on click event of link button i have this code
protected void linkAge_Click(object sender, EventArgs e)
{
Response.Redirect("/Age/");
}
protected void linkName_Click(object sender, EventArgs e)
{
Response.Redirect("/Name/");
}
In IIS i added Application called "Test" and then added all code inside it
When i browse i get to master page as http://localhost:80/Test
When i click on link "Age" the url Changes to http://localhost:80/Age
I expected it to be http://localhost:80/Test/Age
What is wrong that i am doing? Can i achieve this without using any code changes.
Try to use http://localhost/Test/ (with slash in the end) link in to Your browser.
You need to add a tilde (~) to get URLs relative to application root:
Response.Redirect("~/Age/");
BTW: Why do you need to have the redirect behind a post-back? You could use <asp:HyperLink> instead
Like we do this in mvc to get path from root - Url.Content("~\Action\")
In web form -
protected void linkAge_Click(object sender, EventArgs e)
{
Response.Redirect(Server.MapPath("~/Age/"));
}
You got to think like this i think.
Since you're using only the /Age/ path, with nothing to indicate that you're using a relative path. For code managed by IIS, you'd use ~/Age/Whatever to indicate that you intend to go to Age relative to Test.

ASP.NET and C# Redirect

I am working on a project for school, and this is an extra credit part. I have a project started in VS 2010 using master pages, and what I'm trying to do is get a "Submit" button to redirect people to the "MyAccounts.aspx" page. My current code for the ASP part for the button looks like this:
<asp:Button ID="btnTransfer" runat="server" Text="Submit"/>
I have tried adding in the OnClick option, as well as the OnClientClick option. I have also added this code to the Site.Master.cs file as well as the Transfer.aspx.cs file:
protected void btnTransfer_Click(object sender, EventArgs e)
{
Response.Redirect(Page.ResolveClientUrl("/MyAccounts.aspx"));
}
When I run this and view the project in my browser, the whole thing runs fine, but when I click on the "Submit" button, it just refreshes the current page and does not properly redirect to the MyAccounts page. Anyone have any ideas for me?
You are doing it almost correctly, you just haven't put the correct pieces together. On Transfer.aspx, your button should be:
<asp:Button ID="btnTransfer" OnClick="btnTransfer_Click" runat="server" Text="Submit"/>
and your code behind should be like what #KendrickLamar said:
protected void btnTransfer_Click(object sender, EventArgs e)
{
Response.Redirect("~/MyAccounts.aspx");
}
The OnClick event tells it what to execute on post-back when the users clicks the button. This is in the code-behind for Transfer.aspx, not the site master.

Validation of viewstate with GetCompiledPageInstance

on Default.aspx I wrote this code it succesfully shows me Webform1.aspx but it has also one button when I click on that button it give me error
protected void Page_Load(object sender, EventArgs e)
{
var pageView = PageParser.GetCompiledPageInstance("~/WebForm1.aspx", Server.MapPath("~/WebForm1.aspx"), HttpContext.Current);
(pageView).ProcessRequest(HttpContext.Current);
}
Error on button click
Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that <machineKey> configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster.
I think you should try these:
define the following parameter in your both page directives after # Page in your .aspx files.
EnableViewState="false
Then add this in your webcofig in the system.web tag:
and modify your pages tag if exists or add as follows:
I do think it will serve your purpose.
PS: I am using all above in my own project in which I am creating instances of many webusercontrols in side my application and it works fine!

ASP.Net Web application dll loading issue

I have a custom dll loaded into my web application, I updated it and reloaded the reference in my main web app. Basically the way it works is a user uploads a file that gets checked by a function in the dll. The user can then click a button on the results section that redirects to the main section of the app so they have a choice of rerunning the checker; I say section because the web app uses a single page with two divs, one for the form and one for the results, the code behind then swaps the visibility of the form div from the results div, here's the basic layout to clarify.
<body>
<div id="divForm" style="visibility: visible;">
</div>
<div id="divResults">
</div>
</body>
The redirect call is in the code behind as follows:
protected void btnReturn_Click(object sender, EventArgs e)
{
Response.Redirect("http://localhost/file_checker/");
}
And the main piece of the file checker:
protected void Page_Load(object sender, EventArgs e)
{
divForm.Visible = true;
divResults.Visible = false;
if (Page.IsPostBack)
{
//Do file checking
//Show results
divResults.Visible = true;
divForm.Visible = false;
}
}
The web app works fine on the first pass, however, I notice strange behavior after every subsequent pass. For example, I notice that the results page shows stale content from an older version of dll, i.e. It displays a string that was generated by an older version of the dll, I had removed the string and yet it still gets generated. I'm not sure if I'm redirecting correctly or if there's some other fundamental misunderstanding I have with how redirects work. Any help or insight is appreciated.
UPDATE:
Ok, instead of redirecting, I just cleared a gridview in my results section and swapped the styles of the divs to show the main section and hide the results section as follows:
protected void btnReturn_Click(object sender, EventArgs e)
{
//Clear the Gridview and show the upload Form
GridView1.DataSource = null; //<--Is popoulated by a DataTable
divForm.Visible = true;
divResults.Visible = false;
//Response.Redirect("http://localhost/file_checker/");
}
That seems to fix the problem, a lingering question I have is, I'm using a Datatable to populate the Gridview in the results page. Does the Datatable automatically dispose itself after each page load or button click event? Or will it persist? I just want to avoid any memory leak issues, since each page load instantiates a new DataTable object.
A Response.Redirect sends a 302 response to the browser. The browser then makes a new request to the new location. So it isn't a server side operation, and the browser can cache the response and not make the call again. Try appending a querystring parameter to make the browser do a true request. If you have fiddler available, you might use that to verify, but you are probably getting the page from cache.
protected void btnReturn_Click(object sender, EventArgs e)
{
Response.Redirect(String.Format("http://localhost/file_checker/?{0}", DateTime.Now.Ticks));
}

Categories

Resources