Thanks Bruce.
My problem is I am having one TextBox and Delete Button .
I have to check if Textbox.text is empty then display error message if
not then give prompt to user
"Are you sure u want to delete user".If user clicks OK then call Code
Behind function else not.
On Mar 7, 4:19 pm, bruce barker
<brucebar...@discussions.microsoft.com> wrote:
> when you attach code to the onclick, the browser generates an anonymous
> fuinction:
>
> <input type="submit" onclick="doSomething();">
>
> the browser generates the following code
>
> domObj.click = function() { doSomething(); }
>
> you can see the anonymous function does not return any value, so no matter
> what you function returns it has no impact. the following code:
>
> <input type="submit" onclick="return doSomething();">
>
> the browser generates the following code:
>
> domObj.click = function() { return doSomething();}
>
> which will cancel the postback if doSomething returns false.
>
> -- bruce (sqlwork.com)
>
> "ABHIJIT B" wrote:
> > Hi All,
>
> > I am calling Code behind file function in one of JavaScript method as
> > given below,
>
> > I don't want to call Code behind file function during Page Load.
>
> > Kindly help me out for same.
>
> > I tried to call btnDelete.Attributes.Add("onclick",
> > "javascript:vDelete();");
> > in if(IsPostBack) and if(!IsPostBack).Still Code Behind function is
> > called.
> > ---------------------------------------------------------------------------------------------------------------
> > ASPX Code :
>
> > function vDelete()
> > {
> > debugger;
> > window.alert("Hi");
>
> > var loginid = document.getElementById('<
> > %=txtCFirstName.ClientID%>').value;
> > window.alert(loginid);
>
> > if(loginid == '')
> > {
> > window.alert("Hello");
> > document.getElementById('<%=hidUserDel.ClientID%>').value =
> > "N";
> > return false;
> > }
> > else
> > {
> > var ret = window.confirm('Are you sure you want to delete this
> > record?');
>
> > window.alert(ret);
>
> > document.getElementById('<%=lblMUSaveError.ClientID
> > %>').innerHTML = "";
>
> > if(ret == true)
> > {
> > window.alert("Fine");
> > document.getElementById('<%=hidUserDel.ClientID%>').value =
> > "Y";
> > <%DeleteUser();%>;
> > return true;
> > }
> > else
> > {
> > window.alert("Hello");
> > document.getElementById('<%=hidUserDel.ClientID%>').value =
> > "N";
> > return false;
> > }
> > }
> > }
> > ---------------------------------------------------------------------------------------------------------------------------
> > Code Behind File :
>
> > protected void Page_Load(object sender, EventArgs e)
> > {
> > if(!IsPostBack)
> > {
> > //code
> > btnDelete.Attributes.Add("onclick",
> > "javascript:vDelete();");
> > }
>
> > }
>
> > protected void DeleteUser()
> > {
> > try
> > {
> > if (hidSave.Value.ToString() == "0")
> > gvUsersList.Rows[0].Cells.Clear(); //GridView
> > }
> > catch(Exception ex)
> > {
> > //Loggin error in txt file
> > }
> > }
|