.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Post New Web Links

how to do a javascript alert from a another public class

Posted By:      Posted Date: October 22, 2010    Points: 0   Category :ASP.Net

I'm using the ReportGenerator.cs class and this class is referenced from the actual calling page Default.aspx and Default.aspx.cs

using GeneraReport;

in the Default.aspx.cs

and the code in GenerateReport.cs:

namespace GeneraReport
    public class ReportGenerator

This namespace has no reference to Page

However I need to be able to do the following in the public class:

      if (dt.Rows.Count == 0)
                        string Script = "";
                        Script += "<script language=JavaScript id='NoRows'>";
                        Script += "alert('No Rows Found in Query');</script>";

View Complete Post

More Related Resource Links

return class to javascript from webservice?

Hi,I know i've seen a tutorial for this, but can't locate it anymore. I have a class Employee in c# side, I also have a webservice where I pass in an ID# and an Employee object is returned. Now I want this object returned to Javascript code, I know I've seen it done before, can someone point me to a tutorial that shows something like this being done. I'm using the MicrosoftAjax.js file.Thanks.

Load Javascript/CSS from C# Class Library

Can anyone help me figure out how to load Javascript/CSS from my Class Library onto my .aspx pages? Is it possible?Thanks

Font on Page Becomes Bold After Javascript Alert -- Why?

In .Net 3.5   I have a web page that has several checkboxes, text boxes, dropdown boxes etc on it.  When a user clicks on the search button, I run some basic validation on the page. If any validation fails, I invoke a javascript alert letting them know what they did wrong and I return them to the page. However, when the page reloads, all of the text on the page is now larger and bold, even the text inside the menu and which resides in a master page.  I removed every instance of the word "bold" from the project but it still becomes bold after the alert fires. Any idea what could be causing this to happen?  It shouldnt matter but here is a sample of the alert I use: Response.Write("<script language='javascript'>alert('You must check at least one column to display');</script>") Any help is greatly appreciated. thanks

Javascript Alert after closing a modalpopup



I have a linkbutton 'Forgot Password?' in my login page. On click of the link button  a modal popup will open . In that user has to give his username.

If the username doesnot exists  i want to show an alert 'Usename doesnot ' exists. 

Since the checking for the existenance of the username is on click of the button submit which is inside the modal popup, i can show the alert using the code

Page.ClientScript.RegisterStartupScript(...) . But I want something different

I want to call the javascript function after the maodal popup extender is closed

Please help me.



how to apply a css class on html span tag in javascript?



I'm trying to apply a css class on an html span tag in javascript, like below-

$('#company-info').css("class", "help");

But this line of code isn't working!

Can anyone let me know the right way of doing this?



Determine CSS class, set by javascript, server-side


 I have a website and I use javascript/jQuery to change the CSS classes associated with various controls on the page to hide and displey them based upon user selections.  I want to be able to determine the current Css class for an item on my page when the page is posted back to the server.  Is there any way to determine the current Css class for a control on the server when it's been changed using javascript client-side?

Any suggestions would be greatly apprciated.



javascript alert window when dropdown field is selected,



is there a way..where an alert window prompts up to remind the user to select a checkbox when one field in dropdown is selected..for example

there is a dropdown field(Status)  which contains (Tobe confirmed, confirmed and rejected ), when confirmed is chosen..an alert window prompts up reminding the user to select a checkbox(send email) - Yes or No. It is not compulsory for the user to select the checkbox, but if Yes is chosen, the workflow will send an email

javascript not working in sharepoint Public IPhosted site ?




Can AnyBody guide me why Javascript is not functioning in my hosted site with Public IP and i had 3rd party tools using the javascript which they were displaying but functionality.


Pls help me to resolve this !!!!

Thanks in Advance !!! Cheers !!! Praveen Mandalapu

New public class in namespace (web service, asmx)



I have a working web service written in C#.NET that was set up by my predecessor, and have been able to successfully modify it in the past. It works without problems in production.

Basically, the service takes XML code and sends it to a postURL with an outside vendor API. They send back an XML document that we then parse out.

My issue is that I need to connect to another vendor API concurrently with the existing one.

Method 1) Should I create an entirely new Web Service for the new vendor? I tried this but there seemed to be an issue with the ports, having them run at the same time. Should I try again? Any port secrets?

Getting stuck on Method 1, I'm on to Method 2 now....

Method 2) Modifying the exiting web service by adding a new public class to the namespace. I also modified the wsdl, disco and discomap files for the new service. It did compile, but something is missing.

Service1 = exisiting, working web service

https://servername/Service1.asmx - works beautifully and lists all my API calls

https://servername/Service1.aspm?wsdl - shows my wsdl file

Service2 = new, copied web service

javascript script works with alert() and does not fully work without it



Im facing the following problem i have a gridview that i insert an OnClick event to each row in order to be able to click on a row and selecting that row (change the color of the selected row e.tc) my javascript works fine when i have an alert when i remove the alert

then i see the color of the row changing as i click it but then when i move the mouse the color changes back to normal i still get the id of the row since i have a textbox where i put the id content of the e.row.cell[0] value .

I searched the web and i found out that its something to do with ajax and asychronous calls here is the code if the alert is enabled everything works fine this function is called from .c#

protected void GrdEntal_RowDataBound(object sender, GridViewRowEventArgs e)
            if (e.Row.RowType == DataControlRowType.DataRow)

                e.Row.Attributes.Add("onclick", "javascript:getID('" + e.Row.Cells[0].Text + "', '" + e.Row.ClientID + "', '

Javascript alert vs postback


My aim is to not cause a postback if a session var does not equal a certain value when the user clicks the DELETE button. But this causes a postback regardless after the javascript alert is invoked.

I guess I need another logical scenario?




Using JavaScript class AND cssClass



I'm using some JavaScript that's called by the class function within a hyperlink control:

<asp:HyperLink ID="HyperLink_MenuSubLink_AddNewOfficial" runat="server" class='colorbox_AddNewOfficial' NavigateUrl="~/secure/club-officials/add-new-official.aspx">Add New Official</asp:HyperLink>

Thing is, I also want to apply the styles I've created for this and other links like it using:


But if I add that, the JavaScript stops working.

Any thoughts?

Thanks as always




I am trying to learn how to pass a JavaScript object to a server side class and have been successful when it is a simple JavaScript object.  

Suppose I have this Person class:

public class Person
  public string FirstName { get; set; }
  public string LastName { get; set; }
  public string Address { get; set; }
  public string City { get; set; }
  public string Zip { get; set; }

And this web service method:

  public void AddPerson(Person NewPerson)

On the client I can create a JavaScript object like the one below and then pass it to the server. On the server side the Person class will have all properties populated by the values in the JavaScript object.

"{"NewPerson":{"FirstName":"Jon","LastName":"Doe","Address":"15 Stanley Road","City":"AnyCity","State":"AnyState","Zip":"55555"}}"

This all works fine and as you can see the JavaScript object and the Person class have no collection (array) properties.  

However, I would like my Person class to have a collection of phone number. So I person could have a home

javascript alert msg


I have an app with many pages where in the page load event I check for a session variable   Session("usr") being populated or not.

If it is not I then use the following few lines of code to initiate a JS function that is loaded into each page via an include statement.

It works fine, except for this one page.  Any ideas:


Code Behind:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

Dim bldvw As base = New base

Dim cm As ClientScriptManager = Page.ClientScript

Dim cbReference As String

 'see if session has timed out

If bldvw.validateUsr = 0 Then

If (Not ClientScript.IsStartupScriptRegistered("")) Then

cm.RegisterClientScriptBlock(Me.GetType(), "alert", "logout();", True)  

' above line is actually hit each time, but the alert msg never comes up

End If

End If

<-- more code  irrelevant to this task--->

end sub

Public Function validateUsr() As Integer

If Session("usr") = "" Or Session("usr") = Nothing Then

validateUsr = 0


validateUsr = 1

End If

Return validateUsr

End Function




how to use javascript message("alert) in System.Web.IHttpHandler


hello every one i using system web handler when System.Web.IHttpHandler

           save the record than how can show message "Record is saved"

multiple line javascript alert in codebehind c#


I'm trying to put line breaks in my alert that's in a Response.Write like this:


Response.Write("<script>alert('" + dr["display_title"].ToString() + "\n is " + dr["display_title"].ToString().Length + " characters. Title cannot exceed 100 characters. Please limit all titles to 100 characters or less.')</script>");


with the \n  character, but instead of the alert showing up on multiple lines in the dialog box, the alert itself is breaking up into multiple lines like this:

alert('some text

more text

more text')


How would I get this to work correctly? Thanks

What is the difference between " public class ClassName" and " public partial class ClassName : Syst


I m new to the asp.net, my query is what is the difference between between " public class ClassName " and " public partial class ClassName : System.Web.UI.Page"?

as we already know these are the ways of defining the class,.. but my actual query is what will be the difference caused if we add ": System.Web.UI.Page" to the class name,.. as i have done some research and found that we can't use page contents without adding ": System.Web.UI.Page ",..For Example:  we can't use cookie in simple class without adding ":System.Web.UI.Pag"

Please clear me about this confusion,... 

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend