Hi All,
-
I have user control with some standard HTML tags. On one of my HTML button tag I want to perform a javascript validation (a Hello test function for now). I cannot figure out how can I trigger this function from with in my user control on this HTML button tag click event or on usecontrol's click event. Thanks in advance.
Partial Class MyUserControl Inherits System.Web.UI.UserControl Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim js As StringBuilder = New StringBuilder() js.Append("") js.Append("function Hello() { ") js.Append(" alert ('Hello'); }") js.Append("") If (Not Page.ClientScript.IsStartupScriptRegistered("MyScript")) Then Page.ClientScript.RegisterStartupScript(Me.GetType(), "MyScript", js.ToString()) End If End Sub End Class
-
I have user control with some standard HTML tags. On one of my HTML button tag I want to perform a javascript validation (a Hello test function for now). I cannot figure out how can I trigger this function from with in my user control on this HTML button tag click event or on usecontrol's click event. Thanks in advance.
Partial Class MyUserControl Inherits System.Web.UI.UserControl Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim js As StringBuilder = New StringBuilder() js.Append("") js.Append("function Hello() { ") js.Append(" alert ('Hello'); }") js.Append("") If (Not Page.ClientScript.IsStartupScriptRegistered("MyScript")) Then Page.ClientScript.RegisterStartupScript(Me.GetType(), "MyScript", js.ToString()) End If End Sub End Class
Sorry, I messed up the subject earlier. But I meant to wish everybody. HI.
-
I have user control with some standard HTML tags. On one of my HTML button tag I want to perform a javascript validation (a Hello test function for now). I cannot figure out how can I trigger this function from with in my user control on this HTML button tag click event or on usecontrol's click event. Thanks in advance.
Partial Class MyUserControl Inherits System.Web.UI.UserControl Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim js As StringBuilder = New StringBuilder() js.Append("") js.Append("function Hello() { ") js.Append(" alert ('Hello'); }") js.Append("") If (Not Page.ClientScript.IsStartupScriptRegistered("MyScript")) Then Page.ClientScript.RegisterStartupScript(Me.GetType(), "MyScript", js.ToString()) End If End Sub End Class
The easiest way is to use a custom validator, which can be made to call any function you like.
Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
-
The easiest way is to use a custom validator, which can be made to call any function you like.
Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
Christian, Custom Validator!! Sorry, I am not too expert with .net. Could you please explain this with an example? Thanks
-
I have user control with some standard HTML tags. On one of my HTML button tag I want to perform a javascript validation (a Hello test function for now). I cannot figure out how can I trigger this function from with in my user control on this HTML button tag click event or on usecontrol's click event. Thanks in advance.
Partial Class MyUserControl Inherits System.Web.UI.UserControl Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim js As StringBuilder = New StringBuilder() js.Append("") js.Append("function Hello() { ") js.Append(" alert ('Hello'); }") js.Append("") If (Not Page.ClientScript.IsStartupScriptRegistered("MyScript")) Then Page.ClientScript.RegisterStartupScript(Me.GetType(), "MyScript", js.ToString()) End If End Sub End Class
Since your javascript function is not dynamic, it's better to write in page itself than writing from code behind. Write your javascript function on usercontrol. Assume you have a button tag like
<input type="button" id="Btn" OnClick="Hello();">
. This will invoke
Hello()
method when button is clicked.
-
I have user control with some standard HTML tags. On one of my HTML button tag I want to perform a javascript validation (a Hello test function for now). I cannot figure out how can I trigger this function from with in my user control on this HTML button tag click event or on usecontrol's click event. Thanks in advance.
Partial Class MyUserControl Inherits System.Web.UI.UserControl Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim js As StringBuilder = New StringBuilder() js.Append("") js.Append("function Hello() { ") js.Append(" alert ('Hello'); }") js.Append("") If (Not Page.ClientScript.IsStartupScriptRegistered("MyScript")) Then Page.ClientScript.RegisterStartupScript(Me.GetType(), "MyScript", js.ToString()) End If End Sub End Class
just reply the triggering code u hav...
Sarith...
-
Since your javascript function is not dynamic, it's better to write in page itself than writing from code behind. Write your javascript function on usercontrol. Assume you have a button tag like
<input type="button" id="Btn" OnClick="Hello();">
. This will invoke
Hello()
method when button is clicked.
I do not want to write my javascript in the page itself. Validations are different in the case of different parameters passed to the user control. What do you mean by that javascript function is not dynamic..How can I make it dynamic, if that can lead me to the functionality that I want? So, far I was thinking my javascript is dynamic as I have it in page_load and it will be written to the page after form tag is rendered on the page side. Thanks
-
Since your javascript function is not dynamic, it's better to write in page itself than writing from code behind. Write your javascript function on usercontrol. Assume you have a button tag like
<input type="button" id="Btn" OnClick="Hello();">
. This will invoke
Hello()
method when button is clicked.
Well, I have one more question. Like I mentioned based on user control's parameter value I need to perform different client side validation. I could set parameter of user control (have a property, suggest if there is another better way), but how can I use this property value in Javascript? Thanks for bearing with me.