I'm working on making some changes to a Dot Net Nuke website with a customized skin. I found out that the header to the skins file was located in 'Default.aspx' here.
The form has some very strange behavior. I have had to disable the enter button because pressing within the form causes the webpage to go to "/HOME.aspx" however that action is never specified within the Default.aspx.
The code is as follows.
<dnn:Form id="Form" runat="server" ENCTYPE="multipart/form-data" >
<asp:Label ID="SkinError" runat="server" CssClass="NormalRed" Visible="False"></asp:Label>
<asp:PlaceHolder ID="SkinPlaceHolder" runat="server" />
<input id="ScrollTop" runat="server" name="ScrollTop" type="hidden" />
<input id="__dnnVariable" runat="server" name="__dnnVariable" type="hidden" />
</dnn:Form>
The form after being processed displays in the browser as.
<form name="Form" method="post" action="/HOME.aspx" onsubmit="javascript:return WebForm_OnSubmit();" id="Form" enctype="multipart/form-data">
What I want the code to display as is simply.
<form name="Form" method="get" action="/SearchResults.aspx" id="Form">
I tried removing the dnn code with the html directly but removing the dnn form causes the website to crash.
EDIT
What I'm trying to do can be seen at http://www.ontariosheep.org
Notice if you press the button the search works but pressing enter causes the page to refresh.
You can use some Javascript to do this:
jQuery('#SearchBox').keypress(function(e){
if(e.which == 13){
e.preventDefault();CallSearchPage('http://www.ontariosheep.org/SearchResults.aspx');
}
});
You would need to put that in script tags and also in a jQuery document ready area... like
<script>
jQuery(document).ready(function(){
//code above here
});
</script>
Changing the behavior of the form in DNN is not something you are going to do easily. DNN uses the ASP.NET Web Forms model, so the action for the page is always the current page.
If you want to customize this the only real way is to modify the form action via JavaScript on a specific page, but note that doing that prior to a button click or similar trigger WILL break all administration functions on the page that require a postback to the server.
What are you trying to accomplish?
Related
I am using ASP.NET
I have created a user control that look like this:
when pressing the + : the score is raised by 0.5 and the opposite for minus.
The user control contains an update panel, and the pages itself containing the script manager.
When I put this user control in page and NOT inside repeater, this works perfect.
When I put this as part of a repeater. this not work at all.
I tried to delete all the update panels and still not working.
This is the error I'm getting
Don't know how to fix this.
This is the code of the user control:
Often, this error shows due to not post back:
If(!IsPostBack){
// your controls code here
}
Or, Check is your web page not using <form> tag more than once:
<form id="form1" runat="server">
<form id="form2" runat="server">
<!-- Your user controls -->
</form>
</form>
You have to use only one <form> tag in your page.
Or, try in your *.aspx page like:
EnableEventValidation="false"
I have simple aspx page that has a form and a input field in it something like below.
//basket.aspx
<input type="text" id="TotalPrice" runat="server" name="TotalPrice" value="100" />
<asp:button ID="btnBuy" runat="server" Text="make payment" PostBackUrl="~/payment" />
</form>
This is going to payment.aspx but when I debug the Request.Form in the page load of the payment.aspx, I cannot reach the TotalPrice value like Request.Form["TotalPrice"]. What is the best way to make a post to another aspx page to get values ? Why the way I am trying to does not work ?
You should be using PreviousPage property on the target page.
Here is an article on how to make cross post backs work
i worked for long time with windows apps using .net. for last 2 year i am working with asp.net. we often work with asp.net button control. when we click on button then postback occur and right server side event called by asp.net engine. i how link & image button causes postback when user click on those button.
when we work with link & image button then __doPostback js function is called and that causes form submit to server and request the same page and asp.net engine detect which control causes the postback from the hidden input control called eventTarget and invoke right event handler for that control.
but i dont know when we work with asp.net button control like
<asp:Button ID="SampleButton" runat="server"
Text="Submit"
OnClick="ButtonClick" />
when we click button then also form submit but how. i know that in this case __doPostback does not invoke because for button __doPostback is never rendered in the page. so in this case form submit but how asp.net engine detect which button causes postback and invoke right event handler?
how we get the data from textbox like txt1.text when postback occur. is it extracted from viewstate....am i right.
please answer for my 2 question. try to explain here instead of giving any url...thanks.
It's pretty simple with respect to how controls postback. They do it in the same fashion as pure html solutions. There is a Form tag on the page. When the button is pressed it causes the form to submit a postback to the server.
Notice the action target of the form tag, it points to my aspx page
This is all generated by the aspx page itself.
<form name="form1" method="post" action="Default.aspx" id="form1">
<div>
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMjA0OTM4MTAwNGRk5H5eaMNZp5tsD/GQ2iYj2p8J0as=" />
</div>
<div>
<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWAgKmxpCiBgKSotaIC5iWtiHNi+oxYiuBULPgr5d0/WFu" />
</div>
<div>
<input type="submit" name="btn1" value="click me" id="btn1" />
</div>
</form>
Yes asp:button works differently by default. It outputs a standard HTML Submit button which posts back to the Action URL specified on the form. It therefore doesn't use events in the same way as other controls.
However if you add a OnCommand and assign CommandName/CommandArgs to the control, it will then cause the same event based callback behaviour as other controls. The same is true of OnClick. I assumed this used the same process as other controls but actually it's different.
It looks like it uses __VIEWSTATE and __EVENTVALIDATION to determine which form posted back, and the name of the submit button id is posted in the form as part of part of standard HTML form behaviuor. This is what is used to trigger the server-side events.
Scenario:
I have a regular aspx page with a form.
When someone clicks a button the form submitted via post like normal.
HOWEVER. The page where the form resides is the default page(Default.aspx). So when someone goes to the site: http://site.com/ and submits the forms he gets redirected to http://site.com/default.aspx. I tried setting the action of the form to http://site.com/. However asp.net does not allow to use root urls with a POST.
So is there any workaround? Ajax is not an option.
Have you considered creating a plain HTML form? You would need to place your plain HTML form outside the ASP.Net runat=server form on your page.
<form id="form1" runat="server">
ASP.Net controls on your page go here
</form>
<form method="post" action="http://www.site.com">
<input type="text" name="input1" />
<input type="submit" name="input2" value="Submit" />
</form>
I have an html page that I am converting over to an asp .net page. This page contained a form that accesses an external website that I have no control over. There is some sample code below:
<asp:Content ID="sample" ContentPlaceHolderID="body" Runat="Server">
<form name="Subscribe" method="post" action="http://anexternalwebsitehere.com/subscribe.asp">
<input type="text" name="email" size="45" maxlength="120" />
<input type="submit" name="submit" value="Subscribe" />
</form>
</asp:Content>
The form is more complicated than the example I have provided, but it gives a rough idea of what i need to convert over. Here are the problems I have encountered.
If I leave it as is:
When you click on the submit button you have a postback to the current page and not to the external page
If simply convert everything over to be asp form controls and change the postback url:
The id's become some convoluted "ctl00_body_ctl00" which the external page is not able to interpret.
Note: I do need the page to be an aspx page because I am using a master page for other content on the page.
Additional note: this is not Microsoft MVC.
What am I missing?
The issue was with nested forms as others have mentioned.
I was able to fix all my issues by simply doing the following:
Remove the extra form element i was adding.
Leave all controls as simply html controls, except for the submit button.
Replace the submit button with an asp .net button, and set the postback url.
The old code is as follows:
<asp:Content ID="sample" ContentPlaceHolderID="body" Runat="Server">
<form name="Subscribe" method="post" action="http://anexternalwebsitehere.com/subscribe.asp">
<input type="text" name="email" size="45" maxlength="120" />
<input type="submit" name="submit" value="Subscribe" />
</form>
</asp:Content>
The new code:
<asp:Content ID="sample" ContentPlaceHolderID="body" Runat="Server">
<input type="text" name="email" size="45" maxlength="120" />
<input type="submit" name="submit" value="Subscribe" />
<asp:button postbackurl="http://anexternalwebsitehere.com/subscribe.asp" text="Subscribe" runat="server" />
</asp:Content>
This fixes any of the issues with invalid nested forms as there are none. It also addresses the issue of asp .net renaming the asp elements because the only control that is being renamed is the asp button control which was not necessary for the submission to succeed.
Since you probably have the server form tag on your masterpage spanning your contentplaceholder, this new form you're declaring will be placed inside the server-form (by server-form i mean the one asp.net use for postbacks with runat="server")
I've had cases when i needed a special non-server form on an aspx page that already had a server-form, and the way i solved the problem was to place this non-server form outside the server-form - what i mean is, place it after the server-form. Since you use masterpages, you will need a new contentplaceholder on that masterpage, you can call it "noform". It is placed after the server-form so any content put in this noform will be placed outside the server-form. This mean no asp.net controls will work in this specific contentplaceholder (noform) since they won't be picked up by the framework, but you will be able to place your non-server form there and do your magic on that.
The problem, as you've probably guessed, is that you've got one form inside another form - ie the legacy form is appearing inside the ASP.NET form required by the master page.
One quick (if rather clunky) way to get around this is to close the ASP.NET form above the legacy form, and then open a new form below the legacy form. This means you've got three forms on the page, none of which are nested.
So you end up with something like this:
<asp:Content ID="sample" ContentPlaceHolderID="body" Runat="Server">
</form>
<form name="Subscribe" method="post" action="http://anexternalwebsitehere.com/subscribe.asp">
<input type="text" name="email" size="45" maxlength="120" />
<input type="submit" name="submit" value="Subscribe" />
</form>
<form method="post" action="myAspNetPage.aspx">
</asp:Content>
The closing </form> tag at the start closes the ASP.NET from the master page. You then have your form, which should now work as expected. Then the open <form> tag at the end simply ensures that the closing </form> tag from the master page is valid HTML.
Obviously anything appearing on the master page after the legacy form won't be within the standard ASP.NET form, so this may not work for you depending on how the rest of your page is structured.
It's not a particularly elegant solution, but it works as a quick fix (depending on what else is on your master page). We've used it where we had one legacy form required on a site with hundreds of pages, so we simply wanted a one-off fix rather than anything that affected the master page itself.
In our case, we couldn't change the legacy form as this was supplied by a third-party, regularly changed, and needed to be dropped into the ASP.NET page without a developer getting involved to amend it (eg as opposed to Brian's solution to his own question which requires editing the form and is clearly a better option in his case - and probably in most other cases where there is a similar problem).
Your button's click event will handle submission of the url and data.
//C# source
protected void button_Click(object sender, EventArgs e)
}
string customURL = "http://anexternalwebsitehere.com/";
string emailValue = textBoxEmail.Text; //of course validate this for proper email...
customURL += "page.aspx?email=" + emailValue;
Response.Redirect(customURL);
}