开发者

Control button Post Back when click it in ASP.NET with VB.NET

开发者 https://www.devze.com 2022-12-30 02:53 出处:网络
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\"OnCli

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 开发者_JS百科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?


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.


The HTML button should be

<input type="button" value="Save Attributes" onclick="SaveAttributesButton_onclick();">
0

精彩评论

暂无评论...
验证码 换一张
取 消