我能火不费一枪事件页面加载按钮单击事件? [英] Can I fire button click event without firing pageload event?

查看:132
本文介绍了我能火不费一枪事件页面加载按钮单击事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的网页和一个按钮,几文本框从而改变他们的Page_Load事件背景。当我打开页首次它从数据库加载随机数据至文本框与在页面加载的函数,还动态地创建这些文本框。我要的是做对文本框的文本一些变化,然后单击按钮不是发送文本框的新背景下的数据库。但是,当我点击按钮,pageLoad的事件触发一次它重新生成文本框​​和他们的背景下,自然改变,因为它们是新创建的文本框。我试图用如果(!Page.isPostBack),在页面加载但不是创建文本框和相关对象,他们就成为空。

I have a button on my page and and few textboxes which alters their context on page_load event. when I open the page for the first time it loads random data from a database to textboxes with a function in pageload and also I create those textboxes dynamically. what I want is to make some changes on textboxes texts and click the button than send new context of textboxes to database. But when I click on button, PageLoad event fires again and It regenerates the textboxes and the context of them alter naturally since they are newly created textboxes. I tried to use "if(!Page.isPostBack)" in pageload but then the textboxes and related objects are not being created and they become null.

我怎样才能解决这个问题?
我能想到的最好的办法是找到某种方式来触发按钮单击事件不费一枪pageLoad的事件,但我不知道我能做到这一点。

how can I overcome this problem? best thing I can think of is to find some way to fire buttons click event without firing PageLoad event, but I dont know how can I do it.

任何帮助将是AP preciated;)

any help would be appreciated;)

推荐答案

你能再生文本框每个页面加载执行?和数据分配给这些文本框应该在!Page.IsPostback 。所有你需要做的就是保持文本框的ID在的ViewState 只有第一次页面加载和下一再生文本框将有previous存储的ID,你也必须存储在ViewState中对应的数据的ID。有道理?

From Comments

Can you regenerate the Textbox on each Page load Execution? and data assignment to these Textbox should be under !Page.IsPostback. All you have to do is to keep the IDs of the Textbox in ViewState only first time page load and next regeneration of Textbox will have the previous stored ID and you also have to store the ID corresponding data in ViewState. Makes sense?

这篇关于我能火不费一枪事件页面加载按钮单击事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆