views:

27

answers:

2

In my Default.aspx web page i use the following code in order to save some Attributes to an xml file

<asp:Button ID="Button1" Text="Save Attributes" CssClass="Button01" runat="server"  OnClientClick="SaveAttributesButton_Click(); return, false;" >
                        </asp:Button>

when i Click on the button is making post back
I have already use the HTML Button with the same problem
I've change a bit my code like:

    <asp:Button ID="Button1" Text="Save Attributes" CssClass="Button01" OnClick="SaveAttributesButton_onclick" OnClientClick="return, false" >
                            </asp:Button>

And i put the SUB in a script into my page, trying to avoid post back, but nothing

Please is there anybody which can assist me on this issue?

Well Dear Chris Thank you very much for your attention to my issue
I did the following to my page

<asp:Button ID="SaveAttributesButton" runat="server" Text="Save Attributes" CssClass="Button01"  OnClientClick="return SaveAttributesButton_Click;" >
                            </asp:Button>
                           <script type="text/VB" language="VB" runat="server" >

                               Public Sub SaveAttributesButton_Click()

                                   Dim fullpath As String = Request.MapPath(HostingEnvironment.ApplicationVirtualPath)
                                   Dim myXmlWriter As XmlTextWriter = Nothing

                                   Try
                                       myXmlWriter = New XmlTextWriter(fullpath & Strings.Right(XMLFile, Len(XMLFile) - 1), System.Text.Encoding.UTF8)
                                       With myXmlWriter
                                           .Formatting = System.Xml.Formatting.Indented

                                           myXmlWriter.Close()
                                       End With
                                       myXmlWriter.Close()
End Sub
</script>

But the results where the same my button makes Post Back
In my aspx file i have two thinks made
One is that

<input type="button" ID="SaveAttributesButton" runat="server" class="Button01"  value="Save Attributes" onclick="return SaveAttributesButton_onclick();" />

And the other is that

    <script language="javascript" type="text/javascript">
// <![CDATA[

        function SaveAttributesButton_onclick() 

        {
           <%SaveAttributes() %>
        }

// ]]>
    </script>

So, as you may see the first is the button and the second is the Java code
But since i don't know how to programm in Java then i decide to right the name of the Sub which runs in the "behind code file"
In this case when i'm runing the programm my sub runs automatically, but when i'm pushing the button nothing happen
I know that the command pass throu the Java script but she don't execute the line <%SaveAttributes()%>
Can you help me on this?

+1  A: 

The comma in "return, false" causes a javascript error. Instead it should just be "return false;"

Or you can use "return myFunction();" then have the return value of your function determine whether a post back should occur or not.

UPDATE:

What you have with the <%SaveAttributes()%> won't work. You need to make a choice. Either

  1. Go with a regular full post back. I recommend this above the others because of the problems you are hitting with javascript; or,
  2. Learn about AJAX and partial post back events. There are some good articles on this here.
Chris Lively
Dear Chris the comma didn't produce ant error, simply didn't work But please take a look in my last comments in the question section above From the line "In my aspx file...."
Lefteris Gkinis
Updated. By the way, for any javascript work you should use Firefox. Start the Error Console by going to Tools | Error Console. It will show you javascript errors that occur on the page.
Chris Lively
Dear Chris Thank you very much your answer is quit right, the line <%SaveAttributes%> is not working and in order to solve my issue i need to discover the Javascript language.
Lefteris Gkinis
A: 

The HTML button should be

<input type="button" value="Save Attributes" onclick="SaveAttributesButton_onclick();">
Kosta
Kostas Thnak you very much for you answer but please look at then end of my question to where am i stand right now
Lefteris Gkinis