473,657 Members | 2,294 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Calling a DataBind method on a webform in an ascx file

Hey everyone. I was wondering if someone could help me with a small problem.
I have designed a user control and I would have inserted it on a aspz page
(WebForm1). The User control is being used to help with the navigation
through a datagrid. The control handles all the paging issues and on the
webform I do all the DataBinding.

My problem is that at the end of code of an on-click event for a link button
on my user control (DataGridNaviga tion.ascx) I need to call the DataBind
Method. The problem is that the DataBind method is sitting on the WebForm1
code behind page.

Here is a part of my code on the Code behind in the user control (ascx.cs
file) and commented is here I need to call the DataBind method.

private void No1_Click(objec t sender, System.EventArg s e)
{
_currentPageNum ber = int.Parse(No1.T ext);
this.CurrentPag e.Text = _currentPageNum ber.ToString();
ShowHideNavigat ion();
/*Need to call the DataBind method in here somehow
This DataBind Method is sitting on the WebForm1 code behind page*/
}

I would be very grateful if someone could help me please.
Nov 16 '05 #1
4 2316
define a delegate and then define an event and when the link is clicked fire
the event.
The event should then been caught in the page containing the ascx control
and you can re-bind the control as required.

HTH

Ollie Riches

"Stephen" <St*****@discus sions.microsoft .com> wrote in message
news:CF******** *************** ***********@mic rosoft.com...
Hey everyone. I was wondering if someone could help me with a small problem. I have designed a user control and I would have inserted it on a aspz page
(WebForm1). The User control is being used to help with the navigation
through a datagrid. The control handles all the paging issues and on the
webform I do all the DataBinding.

My problem is that at the end of code of an on-click event for a link button on my user control (DataGridNaviga tion.ascx) I need to call the DataBind
Method. The problem is that the DataBind method is sitting on the WebForm1
code behind page.

Here is a part of my code on the Code behind in the user control (ascx.cs
file) and commented is here I need to call the DataBind method.

private void No1_Click(objec t sender, System.EventArg s e)
{
_currentPageNum ber = int.Parse(No1.T ext);
this.CurrentPag e.Text = _currentPageNum ber.ToString();
ShowHideNavigat ion();
/*Need to call the DataBind method in here somehow
This DataBind Method is sitting on the WebForm1 code behind page*/
}

I would be very grateful if someone could help me please.

Nov 16 '05 #2
Stephen,

It sounds like to me that you need to bubble the OnClick event from the user
control. This is pretty simple to do if you have an example or two to follow
I have included a link to a VB and a C# example. I hope that this helps!

---------Links---------
http://www.odetocode.com/articles/94.aspx -C#
http://www.fawcette.com/vsm/2002_11/...efault_pf.aspx - VB.net
Nov 16 '05 #3
Stephen,

It sounds like to me that you need to bubble the OnClick event from the user
control. This is pretty simple to do if you have an example or two to follow
I have included a link to a VB and a C# example. I hope that this helps!

---------Links---------
http://www.odetocode.com/articles/94.aspx -C
http://www.fawcette.com/vsm/2002_11/...efault_pf.aspx - VB.net
Nov 16 '05 #4
Stephen,

It sounds like to me that you need to bubble the OnClick event from the user
control. This is pretty simple to do if you have an example or two to follow
I have included a link to a VB and a C# example. I hope that this helps!

---------Links---------
http://www.odetocode.com/articles/94.aspx -C
http://www.fawcette.com/vsm/2002_11/...efault_pf.aspx - VB.net
Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2261
by: Stephen | last post by:
Hey everyone. I was wondering if someone could help me with a small problem. I have designed a user control and I would have inserted it on a aspz page (WebForm1). The User control is being used to help with the navigation through a datagrid. The control handles all the paging issues and on the webform I do all the DataBinding. My problem is that at the end of code of an on-click event for a link button on my user control...
2
13725
by: adiel | last post by:
Hello, I am trying to access the properties and methods from a user control within the code-behind file for a webform but I am receiving the message: Name 'MenuBar1' is not declared It does not recognize the user control in the code behind... Here is the code for the user control: MenuBar.ascx:
2
2395
by: a | last post by:
Hi Extremely easy question for someone who knows the answer I'm sure :-) (aren't they all) What exactly does LoadControl do? Whats the difference between calling this and just constructing a user control? Thanks anon'ish
3
12014
by: Marty McDonald | last post by:
I have <asp:Table... </asp:Table> on my webform. In codebehind, I populate a DataTable whose data should appear in the asp:Table. I created my own code to populate the asp:Table with the DataTable, then I discovered the asp:Table has a DataBind method. But the method takes no args and so I'm confused how to use it. Is there a link to see how DataBind works for asp:Table? Should I just use my own code anyway? Thanks... Here's my...
0
1139
by: Bryce Budd | last post by:
Hi, I have a webform which has several server controls attached. The entire form is data bound to custom objects. The collection objects are cached using the Cache object. In my use case, I have to update my database, synchronize my cached collection and refresh my UI. After my database update I call dropdownlist1.databind() and my items are exactly the same when they should be less 1 item. If I understand the "control execution...
1
1479
by: Tomislav Bartolin | last post by:
Hi, I have an aspx page which contains an ascx user control. I am using Page.DataBind in Page_Load event of the page to bind elements to page properties. The problem is the ascx uses its Page_Load event to create objects which are then used for data binding, but because I call Page.DataBind in the parent page, the ascx Page_Load event doesn't complete and its objects are null references, so I get errors.
2
1767
by: Jim Bancroft | last post by:
Hi everyone, I have a DropDownList I populate as outlined below. This is from my code-behind file: private void Page_Load(object sender, System.EventArgs e) { BindMyData(); DataBind(); }
0
1575
by: mike | last post by:
How do i perform a databind on a web user control within a repeater or rather how can I access the datasource that is already bound? I have a web user control that displays a table of values (the profile of a piece of equipment) from SQLServer. I've used a repeater on the webform since a query (i.e. by address) against the DB may return multiple machine profiles and I want to use the repeater to display as many machine profiles as are...
2
2109
by: cmay | last post by:
A common situation I come across is an ASCX control that being used as a lookup control. The ascx might be called "StatusLookup" or something, and it consists of 1 dropdown list that populates itself from cache/database list. If you databind on the Init event, then you are databinding every time, and not making any use of the viewstate. If you databind on the Load event, you can see if the control has
0
8407
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8837
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8512
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8612
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6175
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5638
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2739
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1732
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.