thanks
robby
![]() |
0 |
![]() |
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 |
![]() |
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 |
![]() |
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 |
![]() |
hiyou 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 |
![]() |
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 |
![]() |
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 |
![]() |
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 |
![]() |
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 |
![]() |
hi ,
worked
thanks
![]() |
0 |
![]() |
Good! Mark the thread as resolved by which post(s) helped you solve the problem then.
NC...
![]() |
0 |
![]() |
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:
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 |
![]() |