Cancel button in asp.net referal to aspx file - c#

I need help in my asp.net project. I have a "Cancel" button on my page. But it does not work. I have a onclick-function that refers it to a specific page, but when i press it, it askes for validation in the boxes on that page. Whats the problem?

Just add this attribute
CausesValidation="False"
to you Cancel button server side control. This way when the cancel button gets clicked, it will not force validation for the values of your form and you will get what you want.
For further documentation on how this works, please refer to this link:
How to: Disable Validation for ASP.NET Server Controls

Related

ASP Multiview controls

i have some issues right here with ASP Multiview which i can't seem to figure out.
I have this page called Submit.aspx, it is fired up via iframe in AJAX toolkit popup modal extender. I have applied Multiview to this form. When it loads, it will display ActiveIndex 0. If user has clicked the submit button, it will change ActiveIndex to 1 which display "your form has been submitted, etc. and it will auto close via javascript. When i click on Submit link again, the ActiveViewIndex is still stucked at 1, how do i go about programming it to sort of reset/clear the ActiveViewIndex?
You could specifically set the MultiView value with MultiView.SetActiveView(view value)

Detect which button is clicked in Page_Load?

In my asp.net web page, there are a few of buttons and checkboxs. They all can cause postback.
Can I detect which control is clicked? Because I will add code for if clicked a button then do something.
I saw that some examples are done with Jquery.
Can we just do it in C#?
Thanks.
Why are you not just using the click behavior of the button:
ASPX
<asp:Button id="Button1"
Text="Click here for greeting..."
OnClick="GreetingBtn_Click"
runat="server"/>
CS
void GreetingBtn_Click(Object sender,EventArgs e)
{
}
reference here
You could check Request.Form["_EVENTTARGET"] for the control that generated the postback
well if each of the buttons submit a key value to the post or get parameters, and theyre all different it should be pretty easy! :)
localhost/home.html?button=clicked&link=selected
the above is an example of a get parameter url, you can use jquery to get those, or if its a post you would have access to them in a similar way...the previous page would have to have been a form though.
You could eventually do it by checking Request.Form["_EVENTTARGET"] but that is highly unusual and certainly not necessary.
Whatever you need to do, you can do it in the Click event handler of the given control.
You can set a server hidden control specifying the action (checkbox/textbox/button clicked) using javascript & retrieve that server control in page load to check its action & add your code for that action

how to validate tinymce through jquery in asp.net

I have many ascx control files in which I am using the tinymce editor and I am calling all ascx file in one master page on different different btn click.
Now I want, when I click on button A, and I have typed something into the tinymce editor and suddenly I click on button B then the page which is opened on btn click A must ask whether you need to save this text or not on btn click B.
How can I do it with the help of jquery? If there is some other way then please let me know.
I would like you to refer to my answer here....
Using the jQuery Validate plugin with the TinyMCE editor
It will solve your issue of validating the editor client side before sending it to server.
When the user starts editing the content in tinymce editor set a flag isContentChanged to true. Add an event handler to the Button B. In the event handler, you can check for the isContentChanged flag and show an alert that the user is losing unsaved information, if the flag is true. You can use basic JS or Jquery to do this.

create a back button that uses javascript or respose.redirect

Im using asp.net c# (webforms)
I want to add a back button to my page. (you land on this page if you incorrectly fill in a form).
if javascript is enabled i want to go back via javascript, but if it is disabled i'll just do a response.redirect("~/home.aspx")...
how can i implement this? is it 2 buttons? how can i hide the other in the 2 different states if so.
thanks
<asp:Button OnClick="serverMethod" OnClientClick="return(jsMethod);" runat="server" ID="redirectButton" Text="Back" />
on the button, but set the OnClientCLick to:
return(javascriptredirect());
and the OnClick to your button click event handler in your code behind.
if javascript is enabled, it will do the javascript redirect, if not enabled the page will post back and you can do your OnClick code behind method whic can to the response.redirect. You can also return false from your function to prevent the postback from occurring such as the case with setting the OnClientClick="return(confirm('Are you sure?'));"
This link guides you how to do it http://aspadvice.com/blogs/azamsharp/archive/2007/09/30/Check-If-the-JavaScript-is-Enabled-on-the-Client_2700_s-Browser.aspx
Happy coding !!!!!!

ASP.net Text Box Enter button pressed hell

Basically I have an asp.net website with login and search pages.
Currently, I have no idea why, when ever a user hits enter in either of the login text boxes (user name/password) or in the Seach text box, the website is redirected to the default page.
I have no idea why this is happening, I've tried setting defaultButton on both the panel containing the search and the login panel but that doesnt seem to work.
I've also tried catching the key press event with javascript which isnt working either.
I have no idea what event is being fired and why, or why it seems to override everything I try to do.
Anyone seen anything like this before?
---------------Edit-------------------
<div class="searchBar" onkeypress="javascript:return
WebForm_FireDefaultButton(event,'ctl00_MainContent_logView1_LogRepeater_ctl02_lbSearch')">
<input name="ctl00$MainContent$logView1$LogRepeater$ctl02$ctl02" type="text" />
<a id="ctl00_MainContent_logView1_LogRepeater_ctl02_lbSearch" href="javascript:__doPostBack('ctl00$MainContent$logView1$LogRepeater$ctl02$lbSearch','')">
Search</a>
</div>
Ok so here is the code generated by ASP.net that is getting ignored.
---------------Update----------------
I have tried adding a hidden button and setting that button as the defaultbutton of the form and that has stoped it from redirecting to the default page each time but this does mean that pressing enter in a text box just reloads the page, which is better but still isnt Ideal.
This may not be an ASP.NET quirk as much as it is a web-browser quirk.
When you press enter in a single-line text field, the browser will submit the form to the action specified in the form tag.
ASP.NET "helpfully" creates a form tag just inside the body tag and puts all body elements inside it...
As far as I know, you can safely remove this form tag; the HTML specification allows fields outside of form tags for use in JavaScript/AJAX operations.
I have seen this behaviour before, it occurred when the first button on the form was the LoginControl. Everytime enter was pressed it would fire the click event for the login and essentially log the user out. Are you using the LoginControl?
In the end I had to add a hidden button before the login control. The hidden button didn't do anything but it prevented the LoginControl from executing.
I had this same problem once. We had a login form that worked fine when a user hit enter. Then at one point we added a search box/button in the menu bar at the top of the page. Suddenly when users would hit enter they would attempt to perform a search. I resolved it by setting the .DefaultButton of the Form for the page to my login button.

Categories