0

I have this ASP.net component:

<asp:Button ID="Button4" runat="server" Text="Submit Entry" CssClass="eventSubmitButton" OnClick="SubmitData"/>

and I'd like to send some additional information to this SubmitData method, implemented in C#. For example, I want to send an int set in the javascript. I've read that the way to do this is extending the EventArgs class.

However, I don't really understand. Sure I can implement a class that extends EventArgs in C#, but how does that help me pass information from my Javascript?

Is there another way to pass arbitrary information during postback?

2 Answers 2

1

Simply assign it to a hidden field in javascript and read it using Request.Form["FieldName"]

Sign up to request clarification or add additional context in comments.

2 Comments

Sorry if this is a stupid question, but does it take extra time for the server to get that info from the client? Or does it already "have" that info?
Ha, beat me to it. Posting an extra hidden field will not be an issue.
0

CommandArgument property for button is used to pass EventArgs, though its a ServerSide property and cannot be accessed through Javascript.

I believe, best way would be to use a hiddenfield and set value through JavaScript. Here's the sample code...

<script type="text/javascript">

function SetHiddenField()
{
document.getElementById('hfSample').value = "value to assign";
document.getElementById('form1').submit();

}

</script>


<body onload="SetHiddenField();">
<form id="form1" runat="server">
<div>
<input id="hfSample" type="hidden" value="" />
<input id="btnSubmit" type="button" onclick="SetHiddenField();" />
</div>
</form>
</body>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.