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 SharmaRank #223 · 11.1K reputationPosted Jun 3, 2013, 1:41 AM EDT
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 SharmaRank #223 · 11.1K reputationPosted Jun 3, 2013, 12:42 AM EDT
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.
Kiresh Gangariya52 reputationPosted Jun 3, 2013, 12:50 AM EDT
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,
---------------
Dorababu MekaRank #457 · 5.5K reputationPosted Jun 3, 2013, 1:07 AM EDT
Sunny SharmaRank #223 · 11.1K reputationPosted Jun 3, 2013, 2:51 AM EDT
Dorababu MekaRank #457 · 5.5K reputationPosted Jun 3, 2013, 3:07 AM EDT
Sunny SharmaRank #223 · 11.1K reputationPosted Jun 3, 2013, 10:21 AM EDT