I have a webpage with a control to handle all the comments so I don't have to copy the code from one page to another. When I click the button, the code to handle the submit is not happening. I want the page to have no .axd references.
This is my form statement on the .aspx page
<form id="formAlpha" method="post" runat="server" action="">
<Comm:Comm ID="comments" runat="server" />
</form>
The processing for saving the comments is in the control.aspx
In the code of the webpage, I set the action to be
formAlpha.Action = Request.RawUrl;
This is my submit button in the control.
<asp:button ID="cmdSubmit" CausesValidation="false" UseSubmitBehavior="true" text="Submit" runat="server" OnClick="cmdSubmit_Click" OnClientClick="return ValidateSubmission();" />
The JS code executes correctly, it displays an alert box and then returns true. THe page reloads but the click event doesn't work. The load event fires up again and the IsPostBack is false. Its not submitting but reloading.
I'm using WebForms C#, not MVC
Just an idea taken from the official MSDN page, remove the "return" (and maybe the semicolon too) keyword from the onClientClick declaration:
OnClientClick="ValidateSubmission()"
Related
I have defined form action in my asp page and with in form, I have defined the Textbox OnTextChanged. but when I type any thing on Textbox and click on tap to move next.. automatically instead of calling OnTextChanged ..my form action calls..
my code is below
<form id="WebToLead" action="https://url" method="POST" runat="server">
<asp:TextBox id="a" name="a" maxlength="10" runat="server" OnTextChanged="a_TextChanged" AutoPostBack="true" />
// some more textbox
<asp:Button ID="Button2" Text="Click" width="50px" runat="server" OnClick="Button2_Click" />
</form>
Means it action should be triggered on button2_click but it does when i type anything on aand tap to other fields
Ensure you have viewstate enabled for this to work, otherwise Asp.Net has no way of knowing whether the control's value has changed.
AutoPostBack is enabled thats why it is posting the form back to server. Remove it or disable it. It should work after that.
I have button in my page that when click on fires a jquery method that shows a div, but if the browser doesn't support javascript I want to fire a code behind method (using a postback). Is this possible? I'm already using this code but i can't see any results:
<asp:Button ID="Button1" runat="server" Text="Upload Files Here" Width="187px" onClick="CodeBehindMethod" OnClientClick="show_upload_box();return false"/>
and this is my jquery code:
function show_upload_box() {
$("#pop_up_background").css({
"opacity": "0.4"
});
$("#pop_up_background").fadeIn("slow");
$("#signup_pop_up_box").fadeIn('slow');
window.scroll(0, 0);
}
If the browser doesn't support JavaScript then your button would not work.
In ASP.NET, the runat="server" instruction is actually tied to a JavaScript method that submits a form (view page source to see that method).
Change or remove the value of that property to prevent the post back to your server.
I can open another window to display some stuff, but then I cannot use the buttons on the original page anymore. Why is this and how to fix it? This is my code:
<asp:Button ID="Button_ViewSimpleRequest" Text="Simple Request" runat="server" OnClientClick="window.document.forms[0].target='_blank'" PostBackUrl="~/xyz.aspx" />
<asp:Button ID="Button_Self" Text="Self" runat="server" OnClientClick="window.document.forms[0].target='_self'" />
After clicking the first button, the second button also redirects to xyz.aspx. How do I make the second button behave like a normal button on the original page?
I tried: <asp:Button ID="Button_ViewSimpleRequest" Text="Simple Request" runat="server" OnClientClick="window.open('xyz.aspx', 'name')" /> which is simple, and seems to work.
I found my solution by studying How to launch another aspx web page upon button click.
I need to redirect the user to paypal account. But before that I want to collect name and email for that user. So I am using the following code.
<form id="paypalForm" method="post" action="https://www.paypal.com/cgi-bin/webscr"
target="_top" runat="server">
<div>
<label>
Full Name:<span>*</span></label>
<asp:TextBox ID="name" runat="server" CssClass="large form-poshytip" title="Enter your Full Name."></asp:TextBox>
<label>
E-Mail:<span>*</span></label>
<asp:TextBox ID="email" runat="server" CssClass="large form-poshytip" title="Enter Email Address."></asp:TextBox>
<input type="hidden" name="cmd" value="_s-xclick" />
<div id="partnerFormButton">
<br />
<asp:ImageButton runat="server" Name="btnSubmit" Text=" Next "
ID="btnSubmit"
ImageUrl="https://www.paypalobjects.com/en_GB/i/btn/btn_buynowCC_LG.gif"
onclick="btnSubmit_Click" CausesValidation="False" ></asp:ImageButton>
</div>
</div>
</form>
Code Behind code:
protected void btnSubmit_Click(object sender, ImageClickEventArgs e)
{
//some code
}
But the problem is that OnClick event doesn't firing and it redirects to the specified action url.
What can be the problem?
Thank you so much in advance...!!
It's not how ASP.NET events work. Events are fired after postback is made and you are preventing the postback by submitting the form. You need to decide what to do - either submit data with the form (like what you are doing now) and not use OnClick event or use the event and remove action and method parameters from form.
http://msdn.microsoft.com/en-us/library/ms178472.aspx
To explain it further: an event will not fire right after you click the button. What happens is that a POST request is being made to the same page with the page state passed in the ViewState. In other words - pressing the button in ASP.NET by default works kind of like a link to the same page (it's a veeeery simplified explanation though). Events are fired only after that request is made and after the page is loaded again - see the link above.
What you are doing right now is forcing the request to go to another page. Even though the button 'wants' to do a postback, the action parameter in your <form> points the request somewhere else. Since the postback isn't made and your page isn't loaded again, the event will not fire.
IISTe Technologies is going to introduce a blog for their student and other developers where they can find and share their problem and solution regarding c, c++, .NET java, PHP and others, here you one can find the exact solution of their programming problems.
Basically you have specified the action in the form tag.
You can redirect the page to "https://www.paypal.com/cgi-bin/webscr" in the click event. For if u specif action then you you wont be able to sumbit the data of the for. You won't get the values.
It will never go to the click event code block you have written. Because you are posting the page to paypal page instead of self.
Try this:
Remove action attribute from form.
Write click event as
protected void btnSubmit_Click(object sender, ImageClickEventArgs e)
{
var target = #"https://www.paypal.com/cgi-bin/webscr";
Response.Status = "307 Temporary Redirect";
Response.AddHeader("Location", target);
}
I want to create a simple Yes/No popup window. So I have added a ModalPopupExtender to the .aspx page.
The popup panel's markup is:
<asp:Button ID="btn_yes" runat="server" Text="Yes" onclick="btn_yes_Click" />
<br/>
<br/>
<asp:Button ID="btn_no" runat="server" Text="No" />
For some reason, I cannot get into the function btn_yes_Click, not sure why. Do I have to use Javascript?
I suspect that you are also setting the ModalPopupExtenders OkControlID property to "btn_yes".
As you can see in this related question this will cause the OnClick event not to fire.
There is a chance that the OKControlID Property on ModalPopupExtender tag is specified. Take a look at this topic: The Event Handler of the OK button inside a Modal PopUp is not executing