Hi all I have created a javascript function along with the scripts in a class file using string builder as follows
public static string ShowAlertMessage(string pHeader, string pError)
{
StringBuilder strScript = new StringBuilder();
strScript.Append("");
strScript.Append("");
strScript.Append("");
strScript.Append("");
return strScript.ToString();
}
This method I am calling on each and every page on the button click where ever I required as follows
ClientScript.RegisterStartupScript(this.GetType(), "Popup", Alert.ShowAlertMessage("Hello", "Welcome"), true);
But this is not giving me the output I needed, the one which I converted is the following
http://jquerymsgbox.ibrahimkalyoncu.com/
can some one help me please to achieve my requirement
Loading

Sunny SharmaPosted Jun 3, 2013, 5:41 AM
Below is the rectified code:
---------------------------------
public static string ShowAlertMessage(string pHeader, string pError)
{
StringBuilder strScript = new StringBuilder();
strScript.Append("");
strScript.Append("");
strScript.Append("");
strScript.Append("");
return strScript.ToString();
}
----------------------------------------
that's your code that I've modified a little. You can see the highlights in bold. Now the explanation part comes, your code was doing all fine but it was only registering the script with function. it wasn't invoking the function so that "example" function always remained silent. I just enclosed the function with parenthesis followed by another one to make it auto invokable: (func(){})();
Hope you got the Idea.
Happy Coding :)
Please accept this as answer if it helps!
Thanks.
Sunny SharmaPosted Jun 3, 2013, 2:21 PM
Dorababu MekaPosted Jun 3, 2013, 7:07 AM
Sunny SharmaPosted Jun 3, 2013, 6:51 AM
Dorababu MekaPosted Jun 3, 2013, 5:07 AM
Kiresh GangariyaPosted Jun 3, 2013, 4:50 AM
Just some more modification for dynamic class
function example(strTitle,strContent) {
$.msgBox({ title: '+"strTitle"+', content: '+"strContent"+' });
}
-----------
in Code Behind
---------------
protected void Button1_Click(object sender, EventArgs e)
{
string strTitle = "Some Title";
string strContent = "Some Content";
ClientScript.RegisterStartupScript(this.GetType(), "Popup", "example(strTitle,strContent)", true);
}
Let me and Sunny Know that its working or not.
Thanks,
---------------
Sunny SharmaPosted Jun 3, 2013, 4:42 AM
I suggest you to put JS, CSS files references in the master page with the script code in head section, and just call the function inside the event. A tested solution for you:
in the section:
----------------------------
function example() {
$.msgBox({ title: 'Hello', content: 'Welcome' });
}
-----------
in Code Behind
---------------
protected void Button1_Click(object sender, EventArgs e)
{
ClientScript.RegisterStartupScript(this.GetType(), "Popup", "example()", true);
}
---------------
This will achieve your requirement :)
Thanks.