Click here to Skip to main content
15,893,588 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to use ScriptManager.RegisterClientScriptBlock(ctrlName, Page.GetType(), "msg", _script, false) from Javascript function in OnClientClick="CheckMaxLength(this);" of TextBox.

I want to show my custome PopUp. I am able to use it in .cs but I want it to use inside JavaScript.
Posted
Updated 13-May-13 7:49am
v2
Comments
ZurdoDev 13-May-13 13:52pm    
You likely want to use the OnKeyUp or onBlur events, not OnClientClick.

1 solution

The ScriptManager registers scripts in code behind, all it really does is creates script tags like in HTML, but mostly used when logic is needed to determine is the script should be loaded, or if loading an embedded script inside a DLL.

I recommend that you just use the script tags to register your script first, test your onClientClick, and then play around with the ScriptManager.

Inside your head tags, you register your Javascript


So inside your asp.net button object element, you put the following.
<asp:button runat="server" onclientclick="return CheckMaxlength(this);" xmlns:asp="#unknown" />

If you return true, then the button will click, if you return false, the button will not click

To register a script in code behind, make a client script manager, and pass it to the register
Dim cs As ClientScriptManager = Me.Page.ClientScript
Dim rsType As Type = Me.GetType()
If (Not cs.IsClientScriptIncludeRegistered(rsType, "jquery")) Then
 cs.RegisterClientScriptInclude("jquery", cs.GetWebResourceUrl(rsType, "SC_Standard.jquery.js"))
End If
 
Share this answer
 
Comments
Fayaz7Wonders 14-May-13 4:04am    
Can u plz send it in C# .My Question is I have a TextBox I want to show my custome message once it is exceeding 5000 length in javascript
jkirkerx 14-May-13 12:27pm    
No, I have my own work to do today, besides I just wrote that off the top of my head, I was trying to convey to you that you need to use the client script manager and type to register a script.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900