Ramco Ramco

Ramco Ramco

  • 434
  • 3.4k
  • 556.9k

Error - ShowPopup is not defined

Aug 17 2024 4:08 AM

Hi

  In below code i am getting error

ShowMessage("Success", "Record Saved Successfully", "Success");

public void ShowMessage(String Title, String Text, String Type)
{
    Text = Text.Replace("'", "").Replace("/", " ").Replace(";", " ").Replace(":", " ").Replace(",", " ");
    Text = System.Text.RegularExpressions.Regex.Replace(Text, @"\t|\n|\r", " ");
    if (Common.CommonFunction.IE(Request.Browser.Browser))
    {
        Common.MessageBox.Show(Text);
    }
    else
    {
        ClientScript.RegisterStartupScript(this.GetType(), "Popup", "ShowPopUp('" + Title + "', '" + Text + "','" + Type + "');", true);
    }
}

private void ShowPopUp()
{
    System.Text.StringBuilder sb = new System.Text.StringBuilder();
    sb.Append(@"<script language='javascript'>");
    sb.Append(@"$('#modal_form_horizontal').modal({backdrop: 'static',keyboard: true, show: true});");
    sb.Append(@"</script>");

    ClientScript.RegisterStartupScript(this.GetType(), "JSScript", sb.ToString());
}
C#

Thanks


Answers (1)

1
abufaizur rahman

abufaizur rahman

  • 0
  • 54
  • 0
Aug 17 2024 5:35 AM

The error you're encountering (ShowPopup is not defined) suggests that the JavaScript function ShowPopup is either missing or not defined in the client-side code and not sure about this method "private void ShowPopUp()" ?

Steps to fix the issue

1) Correct the JavaScript Funcation Name to "ShowPopUp"

<script type="text/javascript">
    function ShowPopup(title, text, type) {
        alert("Title: " + title + "\nText: " + text + "\nType: " + type);
        // Or implement your modal popup logic here
        $('#modal_form_horizontal').modal({
            backdrop: 'static',
            keyboard: true,
            show: true
        });
    }
</script>
public void ShowMessage(String Title, String Text, String Type)
{
    Text = Text.Replace("'", "").Replace("/", " ").Replace(";", " ").Replace(":", " ").Replace(",", " ");
    Text = System.Text.RegularExpressions.Regex.Replace(Text, @"\t|\n|\r", " ");
    if (Common.CommonFunction.IE(Request.Browser.Browser))
    {
        Common.MessageBox.Show(Text);
    }
    else
    {
        ClientScript.RegisterStartupScript(this.GetType(), "Popup", "ShowPopup('" + Title + "', '" + Text + "','" + Type + "');", true);
    }
}

2.Ensure that Request.Browser.Browser is returning a valid browser string.