Trying to pass value from ASP.NET JavaScript script to my C# Hidden Field -
i have javascript script inside asp.net web site, , want value function c# backend, using argument pass asp.net hidden field.
here asp.net & javascript code, define hiddenfield , assigns chatmessage
var it, assign value var, , try send value returnliclass()
function. (most relevant lines 1, 13, 14, 17):
<asp:hiddenfield id="chatmessage" runat="server" /> <script type="text/javascript"> $(function () { // declare proxy reference hub. var chat = $.connection.chathub; // create function hub can call broadcast messages. chat.client.broadcastmessage = function (name, message) { // html encode display name , message. var encodedname = $('<div />').text(name).html(); var encodedmsg = $('<div /> ').text(message).html(); var tremp_id = $('<div /> ').text("<%=request.querystring["trempid"]%>").html(); var chatmessage = document.getelementbyid('<%= chatmessage.clientid %>'); chatmessage.value = 'value javascript'; // add message page. $('#discussion').append('<li class="<%=returnliclass(chatmessage.value)%><strong>' + encodedname + '</strong>: ' + encodedmsg + "tremp:" + tremp_id + '</li>'); }; // user name , store prepend messages. $('#displayname').val('<%=returnname()%>'); // set initial focus message input box. $('#message').focus(); // start connection. $.connection.hub.start().done(function () { $('#sendmessage').click(function () { // call send method on hub. chat.server.send($('#displayname').val(), $('#message').val()); // clear text box , reset focus next comment. $('#message').val('').focus(); }); }); }); </script>
the backend function (when debug neither msg
nor chatmessage.value
have values):
protected string returnliclass(string msg) { string test = chatmessage.value; return "redchat"; }
server function execute before html sent client. execute server function js use ajax. check out jquery.ajax.
Comments
Post a Comment