How can i stop a screen refresh after clicking "ok" on alert box ? Also how can i get a prompt box up but not in javascript , in the .cs file ?

thanks

robby

0
robby32
10/14/2008 9:39:43 AM
asp.net.client-side 24353 articles. 2 followers. Follow

12 Replies
1523 Views

Similar Articles

[PageSpeed] 28
Get it on Google Play
Get it on Apple App Store

 set a last line in ur function as return false;

in cs file u can call the alert like

Response.Write("<script language='javascript'>alert('hi');</script>");


Thanks,

Ravi

Mark the answer as Answer if it satisfy the need.
0
polravi
10/14/2008 10:14:33 AM

hi,

try this may this will help u..

Page.RegisterClientScriptBlock("key", "<script language=javascript> alert('hiiii');return false;)</script>");


Rahul Somwanshi,
Software Engineer,
Pune, India.

If this is a right answer to your question then,
do not forgot to ckick on "Mark As Answer"
0
rahulsom11
10/14/2008 10:23:46 AM

i get a runtime error :

 

'return' statement outside of  function.

any ideas on this ?

Also how can i get a prompt box like the one in javascript in the .cs file ...?

thanks

 

 

 

 

0
robby32
10/14/2008 10:24:56 AM
hi 

you can't get the prompt message from cs, it can only avliable from client side,

 any validations write at client sdie and proceed to server side, or from client side use

xmlhttprequest or page methods in ajax to call server side method it will return the result and do validations and proceed

to server


Please Mark as Answer if it helps you
0
naveen
10/14/2008 11:17:18 AM

Hi,

Check out http://forums.asp.net/t/1330491.aspx

Refer the virendra comments.

 

Thanks,

Farooq


Mark as answer if this post helpfull to you.

Don't be afraid to be wrong; otherwise you'll never be right.
0
susain
10/14/2008 11:37:13 AM

1. A JavaScript alert does NOT cause a screen refresh. The control calling it causes this. Note the return false statement which stops the PostBack.
<form id="Form1" method="post" runat="server">
 <asp:button id="Button1" OnClientClick="alert('Hello world'); return false;" runat="server" text="Press Me"></asp:button>
</form>

2. Using Response.Write is NOT the way to render client-side script to the markup since that puts the script ABOVE the page tags which screws up the look of the page.

3. This: Page.RegisterClientScriptBlock("key", "<script language=javascript> alert('hiiii');return false;)</script>"); is an illegal statement and, as you saw, will cause a runtime error because you can only use the return key word INSIDE of a function.

4. As naveen.gummudu pointed out you can NOT do client-side functionalities (message boxes, confirm dialogs, etc) from the server. Who would answer them? The web admin? You can only output script to the browser which will only run once the page has completed rendering into the browser.

5. Tell us more in detail what you are looking for and someone will help you.

NC...

0
NC01
10/14/2008 11:45:20 AM

Hi ,

thanks for the detailed reply ,it makes clear a lot of things

what i am trying to achieve is the following :

i have a gridview on the page with checkboxs on the rows. If the user clicks a button and has no boxes checked then i would like to display a message lets say "Please select a row" , but without the screen refresh after they clear the message

 

thanks

robby

0
robby32
10/14/2008 9:58:07 PM

OK, here is a DataGrid with 2 CheckBoxes and a Button. When clicked, the JavaScript attached to the Button checks that at least one of the CheckBoxes are checked and if not, stops the PostBack.

aspx file

<form id="form1" runat="server">
 <asp:GridView ID="GridView1" AutoGenerateColumns="False" runat="server" OnRowDataBound="GridView1_RowDataBound">
  <Columns>
   <asp:BoundField HeaderText="Value" DataField="ItemValue" ReadOnly="true" />
   <asp:BoundField HeaderText="Text" DataField="ItemText" ReadOnly="true" />
   <asp:TemplateField HeaderText="">
    <ItemTemplate>
     <asp:CheckBox ID="gridCheckBox1" runat="server"></asp:CheckBox>
    </ItemTemplate>
   </asp:TemplateField>
   <asp:TemplateField HeaderText="">
    <ItemTemplate>
     <asp:CheckBox ID="gridCheckBox2" runat="server"></asp:CheckBox>
    </ItemTemplate>
   </asp:TemplateField>
   <asp:TemplateField HeaderText="">
    <ItemTemplate>
     <asp:Button ID="gridButton" runat="server" Text="Click Me"></asp:Button>
    </ItemTemplate>
   </asp:TemplateField>
  </Columns>
 </asp:GridView>
</form>

<script type="text/javascript">
<!--
function gridButtonOnClick(gridCheckBox1Id, gridCheckBox2Id)
{
 var gridCheckBox1 = document.getElementById(gridCheckBox1Id);
 var gridCheckBox2 = document.getElementById(gridCheckBox2Id);

 if ( (!gridCheckBox1.checked) && (!gridCheckBox2.checked) )
 {
  alert('At least 1 CheckBox must be checked');
  gridCheckBox1.focus();

  // Return false stopping the PostBack...
  return false
 }

 // Return true allowing the PostBack...
 return true;
}
// -->
</script>

aspx.cs file

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
 if ( e.Row.RowType == DataControlRowType.DataRow )
 {
  // The ItemValue value is in bound column #0...
  string itemValue = e.Row.Cells[0].Text;

  // The ItemText value is in bound column #1...
  string itemText = e.Row.Cells[1].Text;

  // CheckBox with an ID of "gridCheckBox1" is in column #2 of the Grid...
  CheckBox gridCheckBox1 = (CheckBox)e.Row.Cells[2].FindControl("gridCheckBox1");

  // CheckBox with an ID of "gridCheckBox2" is in column #3 of the Grid...
  CheckBox gridCheckBox2 = (CheckBox)e.Row.Cells[3].FindControl("gridCheckBox2");

  // Button with an ID of "gridButton" is in column #4 of the Grid...
  Button gridButton = (Button)e.Row.Cells[4].FindControl("gridButton");

  if ( (gridButton != null) && (gridCheckBox1 != null) && (gridCheckBox2 != null) )
  {
   // Add the row ID as an attribute so that we will know which row was clicked...
   gridButton.Attributes.Add("RowId", e.Row.DataItemIndex.ToString());

   // Add the JavaScript client-side click handler...
   gridButton.Attributes.Add("onclick",
    string.Format("return gridButtonOnClick('{0}', '{1}');", gridCheckBox1.ClientID, gridCheckBox2.ClientID));

   // Add the server-side click handler...
   gridButton.Click += new System.EventHandler(this.gridButton_Click);
  }
 }
}
protected void gridButton_Click(object sender, System.EventArgs e)
{
 string rowId = ((Button)sender).Attributes["RowId"];
 this.Response.Write("gridButton_Click fired RowId: " + rowId + "<br>");
}

NC...

0
NC01
10/14/2008 11:04:27 PM

hi ,

worked

thanks

 

0
robby32
10/14/2008 11:52:12 PM

Good! Mark the thread as resolved by which post(s) helped you solve the problem then.

NC...

 

0
NC01
10/15/2008 11:25:42 AM

call below line in server side 

ClientScript.RegisterStartupScript(Me.GetType, "alert", "confPromptBox();", True)

 

create this function in client side

function confPromptBox()

{

var resp = window.confirm (Are you sure?');

if(resp)

{

  //do somthing

}

 

}

 

Hope this will Help you


Thanks And Regards,
Manoj Karkera
Zenith Software LTD

Please remember to click “Mark as Answer” on the post that helps you
0
manoj0682
10/15/2008 11:40:36 AM

manoj0682:

call below line in server side 

ClientScript.RegisterStartupScript(Me.GetType, "alert", "confPromptBox();", True)

 

create this function in client side

function confPromptBox()

{

var resp = window.confirm (Are you sure?');

if(resp)

{

  //do somthing

}

 

}

 

Hope this will Help you

That has already been posted at least once before and will NOT work with controls in a DataGrid. Please read the earlier posts first.

NC...

 

0
NC01
10/15/2008 11:46:29 AM
Reply:

Similar Artilces:

OpenSuse 11.3 client having samba issue on OpenSUSE 11.2 box "you can only select local files" error
Hello, I recently put openSUSE 11.3 on a old HP pavilion dv1000 notebook (used to be windows xp). Prior to the 11.3 install I was successfully able to have the dv1000 access a local network computer via a Samba server (running OpenSUSE 11.2, note: haven't touched samba.conf in years). I am also currently able to use a htc evo (android) to connect to the file share on the 11.2 box with no issues. On the dv1000 I keep getting errors such as "remote files not accepted" and " you can only select local files". I can manually create a link in dolphin (...

How can I access < input type="hidden" name="objHidden" id="objHidden" > from a .net server side function
Topic says it all..please help!! Right Click the control in the design view and select run as server control. ...

Can I get rid of the "Do you want to save changes" box?
Hello, We're developing an app in PowerBuilder 6.0 with PFC. We're using the u_dw datawindow controls and update service, and whenever a window closes we get the "Do you want to save changes?" message box. Is there any way to get rid of this message at a global level? I would love it so that my u_lvs, u_tvs, and u_dw never have this. Thanks for any help, Matt On Mon, 14 Sep 1998 08:51:15 -0400, in powersoft.public.powerbuilder.pfc Matthew Culbreth <culbreth@gfscomputing.com> wrote: >Hello, > >We're developing an app in PowerBui...

How can i show a message on screen and after click "ok", no page flash ?
Hi, i the page_load i have checking of date rages and if the date range is incorrect  i want to display a message and when the user clicks ok i dont want the page to flash ( do a postback ) how can i do this ? thanks robby You can use RegisterClientScript function on page_load For more details how to use that, and also other way of doing that, you can get here http://www.codeproject.com/KB/aspnet/ClientServer.aspxPlease remember to click “Mark as Answer” on the post that helps youBest RegardsBrij Mohanhttp://www.dotnetglobe.com Hi ,not exactly what i am looking for .  Th...

Can't get rid of the "box" around my image
Hello, All  I am working with the ASP.Net 2.0 image control to display a small bitmap image on each row of a gridview.  The image is a small, circular icon of varying colors.  The problem is that there is a box shape around the outside of the circular image that shows up when the row's background color is anything but white in the gridview.  I have set the background color of the image control top 'transparent,' but this doesn't seem to do anything.  Is there a way to get rid of the "box" around my image?  I suppose I could c...

How can I set the default permitted extensions in a "Open file" dialog box?
For example when, I open an open file dialog box and there is a label saying: Files (*.html,*jpg) or something like that?  I have an ASP.net  FileUpload control. How can I modify that property?  Thanks in advance. you cannot filter the files that a user can browse when using the fileupload control.Mike Banavige~~~~~~~~~~~~Need a site code sample in a different language? Try converting it with: http://converter.telerik.com/ Hi efrain.net, As banavige said, you cannot filter the files directly. But you can use RegularExpressionValidator control to validate the uploaded...

while saving the file "Save as Type" in SaveDialogBox shows "MicrosoftExcelSheet" and "AllFiles", how can i restrict "AllFiles" and show only "MicrosoftExcelSheet" ..
Below is code written for opening XLFile.  HttpContext.Current.Response.Clear();HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + astr_FileName); HttpContext.Current.Response.AddHeader("Content-Length", abyte_Data.Length.ToString()); HttpContext.Current.Response.ContentType = astr_ContentType; //octet-stream"; or //"application/vnd.ms-excel"; HttpContext.Current.Response.BinaryWrite(abyte_Data);    Udaya.M...

Net::Telnet with username, no password
Hello everyone, I'm trying to use Net::Telnet to connect to a server that has a test account called (appropriately) TEST. It has no password on doing a normal telnet to the server after supplying the username, I am taken to the shell rather than being prompted for my password. The prompt I'm given is: TEST F50:/genii4 $ Heres's the script I wrote: #!/usr/bin/perl -w # use strict; use Net::Telnet(); my $host = "172.16.1.2"; my $user = "TEST"; my $pass = ""; my $t = new Net::Telnet(Timeout => 30, Dump_Log => "/tmp...

textbox1 and textbox1.text ="enter username" when i click to textbox1 with mouse or enter something with keyboard, how can "enter username" can be clear autoamatically ?
hi friends textbox1 and textbox1.text  ="enter username" when i click to textbox1 with mouse or enter something with keyboard, how can "enter username" can be clear autoamatically ? cheersMark as me if my question or my answer can be helpful for you :)  Please take a look at the watermark extender for the textboxhttp://www.asp.net/AJAX/AjaxControlToolkit/Samples/TextBoxWatermark/TextBoxWatermark.aspx Jeev~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~If you get the answer to your question, please mark it as the answer....

RE: Net::Telnet with username, no password
------------------------------------------------ On 29 Jul 2003 11:06:09 -0400, K Old <kold@kold.homelinux.com> wrote: > Hello everyone, > > I'm trying to use Net::Telnet to connect to a server that has a test > account called (appropriately) TEST. It has no password on doing a > normal telnet to the server after supplying the username, I am taken to > the shell rather than being prompted for my password. > > The prompt I'm given is: > > TEST F50:/genii4 $ > > Heres's the script I wrote: > > #!/usr/bin/perl -w ...

How can one suppress the "Could not reformat the document" prompt in VS.NET 2005 Editor IDE for a VbScript file
All --How can one suppress the "Could not reformat the document" prompt in VS.NET 2005 Editor IDE for a VbScript file?I was about to post this as a question; but, then I figured it out. As such, here is a quick problem and solution, just FYI. Problem...How can one suppress the "Could not reformat the document" prompt in VS.NET 2005 Editor IDE for a VbScript file?Here is the scenario.   1. I have file, "MyScript.vbs", loaded in the editor.   2. I copy text from Location-A in the file and paste it into Location-B in the file-- (mind you th...

Where can I get the images used by VS2005 for "Edit, Update, Cancel"; "Select"; and "Delete"
I'm looking for small, elegant images to use in the CommandField of a GridView for Edit, Delete, and Select. Visual Studio 2005 uses images that would be perfect but I don't know where to get the files for these images so I can use them in my own project. From a GridView's Smart Tag, go to GridView Tasks | Edit Columns | Available Fields. Under CommandField there is a sub-tree with three images that are just what I need: "Edit, Update, Cancel"; "Select"; and "Delete". Does anyone know where I can find the files for these three images (.bmp, ,gif, etc.)?     I d...

How can i stop "resident" and "our neighbor at" junk mail?
Hello, Does anyone have experience with requesting that the post office not deliver mail addressed to "Resident" "Occupant" or "Our Neighbor At" etc? I know that (in the name of the almighty dollar) post offices across the nation will gladly deliver bulk mail to anyone with a postal address in towns and cities across the nation. Are there regulations that state the post offices must provide a way to opt-out of this? (If there are, i'd like to know them just to familiarize myself with the specifics of the laws) Has anyone ever signed forms or wh...

How can I get a "variable value" from the "variable name"
Hi All, How can I get a "variable value" from the "variable name" ? For Example: ClassDefinition cd_def VariableDefinition vd_def cd_def = this.classdefinition For li_i = 1 To UpperBound (cd_def.VariableList) vd_def = cd_def.VariableList[li_i] MessageBox ("Variable Name: ", vd_def.name ) MessageBox ("Variable Value: ", "??????????") Next Thanks, Gustavo Which value do you expect to get? pbm_thisusuallydoesnothelp:-)) Philip Salgannik <Gustavo> wrote in message news:4069b28a.30f0.846930886@sybase.co...

Web resources about - How can i stop a screen refresh after clicking "ok" on alert box ? Also how can i get a prompt box up but not in javascript , in the .cs file ? - asp.net.client-side

Resources last updated: 12/11/2015 9:57:48 AM