I currently have the following code that display a jquery growl when the page loads.
<script>
window.onload = function () {
var msg = "My alert message";
jQuery.jGrowl(msg, { life: 5000, theme: 'redgrowl' });
}
</script>
I would like to be able to call a jquery growl function from codebehind, I use a scriptmanager but have so far not been able to get it to work. I have tried this..
var sb = new StringBuilder();
sb.Append(" window.onload = function () {");
sb.Append(" var msg = \"Hello world\";");
sb.Append(" jQuery.jGrowl(msg, { life: 5000, theme: 'redgrowl' });");
sb.Append(" }");
ScriptManager.RegisterStartupScript(this, GetType(), "jgrowlwarn", sb.ToString(), true);
But that does not show anything at all. I have the current code that load on window.onload on the bottom of my page just before end of body, and the jquery.growl.js is in the head tag. What could be wrong?
Related
When I change my dropdown list, I want change a label (lblCustomer).
I don't know how to get value from resource file.Any ideas!?
.text('"<%$ Resources:lblCustomer%>"'); this not work. 10x
$(function () {
$('#<%= ddlCustomer.ClientID %>').change(function ()
{
$('#<%= lblCustomer.ClientID %>').text('"<%$ Resources:lblCustomer%>"');
})
}
);
I had similar problem to this. What I end up doing is registering a startup script that reads the values from the .resx file into a variable in javascript. Then I just reference the javascript variables as I need to.
C# Code:
StringBuilder colModel = new StringBuilder();
colModel.AppendFormat("var uiStrings = {{ captureStart: \"{7}\", captureOK: \"{0}\", captureRegister: \"{1}\", captureBad: \"{2}\", captureRegisterBad: \"{8}\", gridTitle: \"{3}\", gridIsCap: \"{4}\", gridNoCap: \"{5}\", gridDelete: \"{6}\", captureDiffUser: \"{9}\" }};",
this.GetLocalResourceObject("capOK").ToString(), this.GetLocalResourceObject("capRegisterOK").ToString(), this.GetLocalResourceObject("capBad").ToString(),
this.GetLocalResourceObject("gvCaption").ToString(), this.GetLocalResourceObject("gvIsCaptured").ToString(), this.GetLocalResourceObject("gvIsNotCaptured").ToString(),
this.GetLocalResourceObject("gvDelete").ToString(), this.GetLocalResourceObject("capStart").ToString(), this.GetLocalResourceObject("capRegisterBad").ToString(),
this.GetLocalResourceObject("capDiffUser").ToString());
ClientScript.RegisterStartupScript(this.GetType(), "initData", colModel.ToString(), true);
JavaScript:
$("#status").html(uiStrings.captureDiffUser);
Hope this helps!
You can use the GetGolabalRessourceObject Function.
$(function () {
$('#<%= ddlCustomer.ClientID %>').change(function ()
{
$('#<%=lblCustomer.ClientID%>').text('<%=GetGlobalResourceObject("lblCustomer")%>');
})
}
);
I am trying to load jQuery dialog from code behind gridview rowcommand. Looks like javascript function is not firing from code behind.
.vb file
Private Sub grdLoan_RowCommand(sender As Object, e As GridViewCommandEventArgs) Handles grdLoan.RowCommand
If e.CommandName = "pdf" Then
Dim message As String = "This is test message"
ClientScript.RegisterStartupScript(Me.GetType(), "Popup", "ShowPopup('" + message + "');", True)
'ScriptManager.RegisterClientScriptBlock(grdLoan, Me.[GetType](), "MyScript", "ShowPopup('" + message + "');", True)
End If
End Sub
if I use alert in clientscript it is working fine. but JS function not working.
ClientScript.RegisterStartupScript(Me.GetType(), "Popup", "alert("This is test message"", True)
html
<div id="dialog" style="display: none">
</div>
<script type="text/javascript">
function ShowPopup(message) {
alert(message);
$(function () {
$("#dialog").html(message);
$("#dialog").dialog({
title: "jQuery Dialog Popup",
buttons: {
Close: function () {
$(this).dialog('close');
}
},
modal: true
});
});
};
</script>
Yes it was not working, I made some modifications and now its working at my end. If you have a scriptmanager on your page, you can try this:
string message = "This is test message";
string jqueryCodeString = #"<script type='text/javascript'>ShowPopup('" + message + "');</script>";
ScriptManager.RegisterStartupScript(this, typeof(string), "Confirm1", jqueryCodeString, false);
I want to show division for 5 seconds while i do every postback in c#.I am using below function to do that but it doesn't work.
I used this code on page load in c#.
Page.ClientScript.RegisterStartupScript(Page.GetType(), "PostbackClick", "setTimeout(function() { $('#correct').fadeOut(1500); }, 5000)", true);
in aspx page
<script type='text/javascript' src='Scripts/scripts/jquery.min.js'></script>
<script type="text/javascript">
$(document).ready(function () {
$('#correct').hide();
});
</script>
<img alt="" id="correct" src="Que-img/correct.png" />
use
RegisterClientScriptBlock(Page.GetType(), "PostbackClick", "$(document).ready(function(){
setTimeout(function() { $('#correct').fadeIn(1500); }, 5000)});", true)
Because you have to wait for JQuery.ready before using jquery selectors. RegisterStartupScript actually happens before jquery ready.
in my answer your setTimer will executed on jquery ready
You already hiding the image in document.ready function
<script>
$(document).ready(function () {
//$('#correct').hide(); // remove this line or comment
// because fadeOut will work on visible elements
function hideImage() {
setTimeout(function() { $('#correct').fadeOut(1500); }, 5000);
};
});
</script>
In C#
Page.ClientScript.RegisterStartupScript(Page.GetType(),"PostbackClick", "script",
"hideImage();" true);
How to Call Jquery from C# will help you
I guess i got your issue ...Modify your code as below
$(document).ready(function () {
$('#correct').hide();
$('#btnId').click(function(){
$('#correct').show();
setTimeout(function() { $('#correct').fadeOut(1500); }, 5000);
});
});
and remove
Page.ClientScript.RegisterStartupScript(Page.GetType(), "PostbackClick", "setTimeout(function() { $('#correct').fadeOut(1500); }, 5000)", true);
Here is the demo
I am dynamically adding a jQuery multiselect control onto a page like this:
var captionCell = new HtmlTableCell { InnerHtml = control.Caption };
var inputCell = new HtmlTableCell();
inputCell.Controls.Add(inputControl);
var row = new HtmlTableRow();
row.Cells.Add(captionCell);
row.Cells.Add(inputCell);
tbl.Rows.Add(row);
And building my javascript string like this:
StringBuilder sb = new StringBuilder();
sb.AppendLine("<script type=\"text/javascript\">");
sb.AppendLine("var $callback = $(\"#callback\");");
sb.AppendLine("$(document).ready(function () {");
sb.Append("$(\"#");
sb.Append(multiSelectControl.ClientID);
sb.AppendLine("\").multiselect(");
sb.AppendLine("{");
sb.AppendLine("show: \"fade\",");
sb.AppendLine("hide: \"fade\",");
sb.AppendLine("click: function (event, ui){");
sb.AppendLine("$callback.text(ui.text + ' ' + (ui.checked ? 'checked' : 'unchecked'));");
sb.AppendLine("},");
sb.AppendLine("});");
sb.AppendLine("});");
sb.AppendLine("</script>");
Then adding the script to the page like this:
ScriptManager.RegisterClientScriptBlock(this.Page, Page.GetType(), "CreateControl" + inputControl.ClientID,
sb.ToString(), false);
But im getting the following error when trying to do this:
Microsoft JScript runtime error: Object doesn't support this property or method
Please assist guys.
Thanks in advance.
You need to have jQuery included in the page to use document.ready, You did not add the script tag to include jquery in the page, Add script tag to include jquery.
<script type="text/javascript" src="/jQueryFolder/jquery.js"></script>
var $callback = $("#callback");
$(document).ready(function() {
$("#ClientID").multiselect({
show: "fade",
hide: "fade",
click: function(event, ui) {
$callback.text(ui.text + ' ' + (ui.checked ? 'checked' : 'unchecked'));
}
});
});
I solved this by creating a user control, and when I need to use the script above I just loaded the user control.
Solved everything and works really well.
I am working on asp.net c# . I want to add javascript function in c# by using htmlgeneric control .I have used code ,
HtmlGenericControl scriptTagLinks = new HtmlGenericControl("script");
scriptTagLinks.Attributes["type"] = "text/javascript";
string scrip = "$(function () {$([src='" + url + "']" + ").pinit();});";
// txtDesc.Text = rdr.GetString(4);
// TxtLink.Text = rdr.GetString(6);
scriptTagLinks.Attributes["src"] = scrip;
this.Controls.Add(scriptTagLinks);
But i should get like this ,
<script type="text/javascript">
$(function () {
$("[src='/pinterest/portals/0/Images/about-person3.jpg']").pinit();
$("[src='/pinterest/portals/0/Images/about-us-group.jpg']").pinit();
});
</script>
But i am getting this as
<script src="$(function () {$([src='/pinterest/portals/0/Images/about-us-group.jpg']).pinit();});" type="text/javascript">
How can i add $([src='/pinterest/portals/0/Images/about-us-group.jpg']).pinit();}); between tags .