Accessing HTML control/Javascript Function Value In Asp.net Page
Some time situation comes where some Javascript effect/jquery or css make work on html control but not in .net control.
then what to do?Here is the solution to make html control interaction with asp.net control.So that there value can easily access by your asp.net control.
But SomeTime We Have Fuctions Where We Have Value In Cloud And We Have To Catch Then On Fly.
Some time situation comes where some Javascript effect/jquery or css make work on html control but not in .net control.
then what to do?Here is the solution to make html control interaction with asp.net control.So that there value can easily access by your asp.net control.
In Normal Cases
Just Make Input Text(html control) runat="server".
Just Make Input Text(html control) runat="server".
<input id="Text1" runat="server" type="text" />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
Now If You Want To transffer Text1 Value To Label1 Just Do This In Your C# Code(In Any Event)
Label1.Text = Text1.Value;
But SomeTime We Have Fuctions Where We Have Value In Cloud And We Have To Catch Then On Fly.
------------------------------------------------------------------------------------------------------------------
So Here We Start...
Let say you've a html textbox with name txtbox and it has some value...so first thing is we have to save its value to a variable name it C.So that we are sure that the txtbox value is now in a variable and we can pass it to any one.
Next thing is ASP.NET has a control name hiddenControl ,just drag it in your design Page(Because Its Behave As A Mediator Between Html & .Net Control Easily) And finaly.just put that C value in hiddencontrol1
html Control----->var C----------->HiddenControl----->Now Value Is In Your ASP Page!
In HTML
For An Instance Lets Say You Are Firing An Client Side Event(javascript function) Like Below....
<html>
<script>
function yourown()
{
var C=document.getElementById("txtbox").value;
document.getElementById('<%=HiddenField1.ClientID%>').value=C;
return true;
}
</script>
</script>
</html>
In C#
Now Understand The Below Code Where We Are Storing final Value Under HiddenField1 To A string In C# Page
String S=HiddenField1.Value;
Response.Write(S);//Show On Screen
//OR
Label1.Text=S; //Show On Label
No comments:
Post a Comment