开发者

Prevent the page to load elements in the page refresh ASP?

I have a page that add Items to RadioButtonList with this code :

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
RD.Read()
    RBQ1.Items.Add(RD.GetString(3))
    RBQ1.Items.Add(RD.GetString(4))
    RBQ1.Items.Add(RD.GetString(5))
    RBQ1.Items开发者_如何学JAVA.Add(RD.GetString(6))
End Sub

When I click in any button in the same page, the entire page reload and it display 8 items in the RadioButtonList, If I click for the second time I get 12 items in the RBL...

How can I prevent the page to reload if I click in this button. ?

Thanks.


You should only add the items to the control if IsPostBack is false.

If not IsPostBack then
    RD.Read()
    RBQ1.Items.Add(RD.GetString(3))
    ...
End If

As far as not having the page reload - generally when a button is clicked you do want to submit a postback to the server so you can perform whatever action the user initiates with the button.


If you only want to populate the RadioButtonList the first time the page loads, you need to wrap that code in

If Not IsPostBack Then
   // this is the first time the page loads > populate your RadioButtonList here
Else
   // this is when the page reloads after postback
End If
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜