Click here to Skip to main content
15,901,961 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
well I have 2 pages page1 and page2
from page1 after clicking on grid button loads page2 as window

In page 2 I have 3 control: TextBox and 2 Button Save and Close

here is code below

HTML
<script type="text/javascript">
             function returnToParent(result) {
                 var arg = new Object();
                 arg.result = result;
                 arg.text = document.getElementById("txtComment").value;
                 var wnd = GetRadWindow();
                 wnd.close(arg);
             }
             function GetRadWindow() {
                 var mwnd = null;
                 if (window.radWindow) mwnd = window.radWindow;
                 else if (window.frameElement.radWindow) mwnd = 
                          window.frameElement.radWindow;
                 return mwnd;
             }
</script>


<asp:TextBox ID="txtComment" TextMode="MultiLine" runat="server"
     Width="700px" Height="60px" />
<asp:LinkButton ID="lnkSave" runat="server" Text="Save" Width="100%" 
     CssClass="white" onclick="lnkSave_Click" />
<asp:LinkButton ID="lnkClose" runat="server" Text="Close" Width="100%"
     CssClass="white" CausesValidation="false"
     OnClientClick="returnToParent(0); return false;" />

and Code Behind

C#
protected void lnkSave_Click(object sender, EventArgs e) {

            if(!string.IsNullOrEmpty(txtComment.Text))
            {
                // code
                ClientScript.RegisterStartupScript(this.GetType(),
        "CloseWindow", "returnToParent(1)", true);
            }
            else {
               ClientScript.RegisterStartupScript(this.GetType(), 
        "CloseWindow", "returnToParent(1)", true);
            }
}

as you see close button I call javascript function returnToParent(result) and set resalt 0
it warks and does not postback
now I want to do if TextBox.Text is empty that I check it in code behind
if(!string.IsNullOrEmpty(txtComment.Text))

if it's empty it goes to else statement there I try to do it so that not postback with registering script
but there is trouble when I click save button when textbox is empty it postbacks again

How can I do it that not postback?? :(
Posted

Page.RegisterStartupScript("name", "<script>IsEmpty();</script>");


javascript function
<br />
function IsEmpty()<br />
{<br />
var a=$get(clientId+txtComment).value<br />
.<br />
.<br />
.<br />
<br />
}

write the code you need here in javascript
Here you should add the clientId before the controlid for getting the control
I hope this may help you..
 
Share this answer
 
v3
If you don't want the postback to occur when the textbox is empty then you need to check it at the client.
 
Share this answer
 
Comments
Ankur\m/ 12-Jan-11 8:34am    
[moved from answer]
OP wrote:

how? can you write it?
------------------------------------
[no name] 12-Jan-11 9:22am    
Are you asking me to write it for you? How much are you paying?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900