Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
First I create a page with a textbox and a button; when the button is clicked, it redirects to another page.
This is the code for the redirected page:
protected void Page_Load(object sender, EventArgs e)
{
if (Page.PreviousPage != null)
{
TextBox SourceTextBox =
(TextBox)Page.PreviousPage.FindControl("TextBox");
if (SourceTextBox != null)
{
form1.InnerHtml = SourceTextBox.Text;
}
}
}
Now, I've what is written in the text box is displayed but the changes in the form aren't permanent. When I close the page then I open it again, it doesn't display what I have written before.
Is there any way to make the changes in the form permanent when I use .innerHtml?
Not without adding some storage solution. All you're doing here is editing the inner HTML of the form in the single instance of the page being rendered on the server, any other users loading the page will not see your changes, and as you have already discovered reloading the page yourself discards the content and reloads from the server.
You could save the content to a file on the server, store it in a database on your server, or perhaps use an online solution like Google's Firebase if you don't have access your your own DB server.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I've got a large .net form with hundreds of input fields, sometimes users navigate off the form page without saving, what's the best way to check if a field value has changed when they try to navigate away? some c# function or javascript?
Don't take the control out of the users hand :-)
Ask him on exit, if he wants to save the changes. Maybe he did some changes by mistake, which you don't want to save.
You can achieve this by Javascript/Jquery. Something like:
$(document).ready(function() {
formmodified=0;
$('form *').change(function(){
formmodified=1;
});
window.onbeforeunload = confirmExit;
function confirmExit() {
if (formmodified == 1) {
return "New information not saved. Do you wish to leave the page?";
}
}
$("input[name='commit']").click(function() {
formmodified = 0;
});
});
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I have a website where a user logs in, can see his information and edit it. There is also another website, something like a site only for admins, where if I click a link it redirects me to the first website, logged in as that user but I can only read his information not edit it. I am having trouble finding out how to make website 1 both readable only and read/writeable.
I am doing this in Asp.NET mvc using C#.
One method would be to check for authorization in the Razor view.
Psuedocode:
#if(User.IsAuthorizedForEdit()
{
#*your edit view code*#
}
else
{
#*your readonly view code*#
}
This does make for some bloaty Razor. The other (arguably, better) alternative is to direct them to the appropriate view in your controller based on user.
Handy-wavy psuedocode to give you an idea:
public ActionResult ViewProfile(int profileId)
{
var user = GetCurrentUser();//without looking at your code, I can't infer this piece.
var profile = GetProfile(profileId);
if(IsAuthorizedToEdit(user, profileId)
{
return View("edit", profile);
}
else
{
return View("view", profile);
}
}
In theory, you already have a read-only view and an edit view, so the latter would be more reusable.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have something I'd like to attempt, but am unsure of the best path to accomplish it. I have a page, say default.aspx, that creates some content. I also have a second page, say input.aspx, that creates a small select box. This box is to be loaded via ajax on a chang emade on default.aspx. However, I also need this box to initial load in the codebehind of default.aspx.
Example:
1. default.aspx codebehind creates content and loads input.aspx in the codebehind
2. field changes on default.aspx and input.aspx is changed via ajax using Jquery
However, I cannot seem to find the best possible way to load a second ASP.NET page into the codebehind of the initial page. I was considering using an HttpWebRequest object, but am not sure the syntax. Any help would be appreciated.
Thanks!
At Request of #Mbeckish
What I need to happen is outlined below step-by-step
default.aspx loads with content generated from codebehind
Also in codebehind, a select box is loaded (I have this in a separate input.aspx file now. This is the step I need help with.)
default.aspx response is returned and displayed on client
user changes a form value on default.aspx
the select provided by input.aspx is reloaded from server (I currently use a JQuery ajax request to allow this)
Sounds like your second page 'input.aspx' should really be a UserControl (.ascx file), which you dynamically load (using Page.LoadControl(...)) in your default.aspx page.
What you need is to add an iframe to default1.aspx and set it's src property to be the other page
<iframe src="otherPage.aspx"></iframe>
http://www.w3schools.com/tags/tag_iframe.asp
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
How to load index page with QueryString in asp.net? I know that we can redirect to a particular page with QueryString, but what I want is to load first page with some querystring.
If you are setting start action in Property pages of your application then you can follow following steps
1) right click on your project in solution explores
2) Go to Property pages
3) Set start action to 'Specific Page' and value = "index.aspx?a=22"
A very simple way to make it work on both local and remote enviroments is to, at page_load(), detect if the desired QueryString content is present.
If not, Use Response.Redirect pointing to the current page with the added QueryString parameters. Example follows:
if (Request.QueryString["QSEntry"] == null)
Response.Redirect("Page.aspx?QSEntry=desiredValue");
Pro: It'll work the way you want.
Con: You're actually loading the page twice (first time it's a parameterless load), so don't forget to take that into consideration.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
i am using C# and sql database. In db is stored information about items - id, name, etc.
Now i have a page to show items, that i use as a template and pass Item id in the url like /Item.aspx?id=223.
I would like to create pages for every item and save them to folder like /Items/Red-Book.aspx.
Any suggestions?
Thanks, Walt
You don't need to save the pages physically. You only need one page Item.aspx which will generate the content according to the ItemiId you supply. (the same way you explained in the question)
After you have this page you need to look into how to rewrite URL.
What rewrite URL does is that it takes the url that a user requested and rewrites it to something else.
If a user request /Items/Red-Book.aspx the url will be rewrited to /Item.aspx?id=223 and youre ASP.NET will load /Item.aspx?id=223 back to the client.
You can make use of the method RewritePath which you can call at Application_BeginRequest to rewrite your URL.The logic would be as follow:
protected void Application_BeginRequest(Object sender, EventArgs e)
{
var currentPath = HttpContext.Current.Request.Path;
// do some logic to generate newPath
var newPath = GetNewPath ( currentPath );
HttpContext.Current.RewritePath(newpath);
// after this point ASP.NET will work as the user would have requested newpath
}