Sending data from page to another page with a html button - c#

I have problem in sending some value from code behind to another page.
I have an input button that's enabled when the check box is true (write with js) now I want a call event for this button so the code behind that will send some value to another page .
This is my html button:
<input type="button" Class="btn btn-primary pull-left" id="del_event" name="del_event" value="confirm" disabled="disabled">
I have 2 values that need be send in the code behind.
How can I send these values to another page?

If you use just an HTML tag instead of an asp.net button you may use query string. Wrap your button inside an <a> element. Like this:
<input type="button" value="click">

you can use session to keep the value in this page behind ,and then get it in anohter page behind.

Related

how to add hide event to the button in webform?

im trying to hide div by clicking the button, but it does hide it for a second and return the div (looks like it refreshing page).here is my html code :
<div id="page">
<p>First Paragraph</p>
<p>Second Paragraph</p>
<p>Yet one more Paragraph</p>
<asp:Button ID="Button1" runat="server" Text="Button" />
</div>
and here is my jquery code:
$(document).ready(function () {
$("#Button1").click(function () {
$("#page").hide();
});
});
What Rick said in his answer AND you need to add Type="Button" to your button.
<Button ID="Button1" type="button">Button</button>
The default button type is submit, which will cause the page refresh. AND, as Rick mentioned, ASP buttons will also submit. So, you need to use an HTML button and set the type="button" attribute.
From MDN
The type of the button. Possible values are:
submit: The button submits the form data to the server. This is the default if the attribute is not specified, or if the attribute
is dynamically changed to an empty or invalid value.
reset: The button resets all the controls to their initial values.
button: The button has no default behavior. It can have client-side scripts associated with the element's events, which are
triggered when the events occur.
An ASP Button with runat="server" causes a server post-back. If you aren't going to be acting on that click from the server, just use a client-side button like:
<button id="Button1" type="button">Button</button>
Set the client id mode to static on the button, then it'll work. It's not working because that hasn't been specified so the name is changing.
<asp:Button ID="Button1" ClientIDMode ="Static" runat="server" Text="Button" />
If you wanted to disable the postback to simply hide something without processing anything, then just using a client side button is the best option.

Can I send a "click" to an href in asp code behind?

There is a complex function written in jquery that runs if the href below is clicked by the user. Is there any way I can simulate this click in the code behind of the asp form? In other words, I need to "click" the href called "shipping_question_ID_product_received_as_ordered_link" from my code behind to prepopulate this input. Can anyone assist?
<div class="no"><label class="label-1" for="shipping_question_ID_product_received_as_ordered_not_acceptable">Not Acceptable</label></div>
<div class="yes"><label class="label-2" for="shipping_question_ID_product_received_as_ordered_acceptable">Acceptable</label></div>
<label class="universal-label"></label>
<input type="radio" id="shipping_question_ID_product_received_as_ordered_not_acceptable" name="shipping-question-ID-product-received-as-ordered" value="Not Acceptable" runat="server">
<input type="radio" id="shipping_question_ID_product_received_as_ordered_acceptable" name="shipping-question-ID-product-received-as-ordered" value="Acceptable" checked="true" runat="server">
#ArindamNayak had the right idea, but there may be issues with his implementation. If you add the below script to your code-behind, you will achieve what I believe is your desired result:
var autoRunScript = string.Format("<script>$(function() {{ $('#{0}').click(); }} );</script>", shipping_question_ID_product_received_as_ordered_link.ClientID);
Page.RegisterClientScriptBlock("keyClientBlock", autoRunScript);
The difference here is that without wrapping your $(link).click() in a ready handler, jQuery may not process the command correctly. Additionally, you have to be careful with the ID that you use as it could be modified to include containers.
You can use following.
string jScript;
jScript="<script>$('#linkid').click()</script>";
Page.RegisterClientScriptBlock("keyClientBlock",jScript);
So this will add a JS code block programatically to aspx and this JS will execute to click the a href ( having id = "linkid"

How to disable angularjs from capturing my form submit for the second submit button

Thanks for checking.
I am building a web application using angularjs. i have two buttons one will do a Ajax post to server using angularjs and the other will to a normal html post to server. the reason i want the second one to do a direct post to server is that i want to generate an excel document on server and return it tp user to download on response.
please how can i disable angularjs from capturing my form submit for the secont submit button
I'd say that the simplest way is to change the button that shouldn't post the form to not be a form button, but another element that doesn't have that default behaviour. That is, change this:
<form>
<input type="text">
<input type="submit" ng-click="doStuff()" value="Ajaxy things">
<input type="submit" value="Real post">
</form>
to:
<form>
<input type="text">
<a ng-click="doStuff()">Ajaxy things</a>
<input type="submit" value="Real post">
</form>
And style the a to look like a button.

Multiple "OnSubmit" in Form

On the current website I am working on we have a Html Form that wraps everything and is used by the global search to submit and search when the user presses enter in the "global search" text box.
The problem we are now having is that we have a application form which has its own text boxes within this Html Form and when you press enter it does a onSubmit for the Global Search.
So in short I was wondering if there was any way to change certain specific text boxes to do a different onSubmit than the global search.
Many Thanks,
Vincent Kong
Instead of using type="submit" buttons use regular buttons (type="button") then call javascript to do what you want.
you can use HTML5 formaction Attribute:
<form action="demo_form.asp">
First name: <input type="text" name="fname"><br>
Last name: <input type="text" name="lname"><br>
<input type="submit" value="Submit"><br>
<input type="submit" formaction="demo_admin.asp" value="Submit as admin">
</form>
Although this quickly becomes messy, you can set the CommandName attributes on each of your buttons and handle them appropriately (based on the command value of the clicked button) during the postback.

C# Click html submit button with no id

I have a page in my C# webbrowser that contains
<input type="submit" value="Sign out">
Since it does not have an id, I am unable to use the webbrowser's htmldocument to get it by an id and invoke its click. How would I click it using htmldocument now?
You can give it your own ID you know, it's doesn't have to be a server control for that. Just do:
<input type="submit" ID="MySubmitButton1" value="Sign out">
You mention you want to call something when it is clicked, alternatively just add the onclick event manually:
<input type="submit" onclick="CallMyFunction()" value="Sign out">
Pass 'this' into it if you want to pass the input control into the function:
<input type="submit" onclick="CallMyFunction(this)" value="Sign out">
You probably don't want the submit button to post anything when you call your function as well, so you probably want something like:
<input type="submit" onclick="return CallMyFunction()" value="Sign out">
function CallMyFunction()
{
bool IsFormValid = false;
// Check if form is valid
return IsFormValid;
}
Assuming you don't have control over the HTML page and therefore cannot add an ID to the element, you could use the HtmlDocument.GetElementsByTagName to get all input elements, and then filter that collection by the type and value attributes. Something like:
var firstMatchingSubmit = (from input in myDocument.GetElementsByTagName("input")
where input.GetAttribute("type") == "submit" &&
input.GetAttribute("value") == "Sign out"
select input).FirstOrDefault();
if (firstMatchingSubmit != null)
{
firstMatchingSubmit.RaiseEvent("click");
}
Note that this approach is not appropriate if there are multiple matching elements (only the first one will be clicked).
What about this:
webbrowser1.Document.Forms[0].InvokeMember("submit");
How to handle page with multiple html submit button with no id? How to identify the submit button from 2nd row.Multiple html buttons

Categories

Resources