Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sender as object?

Status
Not open for further replies.

gagz

Programmer
Nov 21, 2002
333
US
Hi-

I have a web form that has a link button to allow people to dynamically add more fields (usercontrols to a panel).

Code on the aspx page is:
Code:
<asp:Button id=&quot;AddRoom&quot; onclick=&quot;AddRoom_Click&quot; runat=&quot;server&quot; Text=&quot;Add&quot; CausesValidation=&quot;False&quot;></asp:Button>

Code in my .vb file is:
Code:
Sub AddRoom_Click(Sender As Object, e As System.EventArgs)
            Dim c1 As System.Web.UI.UserControl
            c1 = LoadControl(&quot;/bmc/Library/BreakOutRooms.ascx&quot;)
            c1.ID = &quot;BORooms2&quot;
            BreakOutRooms.Controls.Add(c1)
End Sub

So the form posts back, but in my ispostback conditional, thats where I want to do the form processing... this button should just be adding controls... is there anyway to figure out what control fired the event so that I could just add that as a condition to my ispostback condition?

Code:
if page.ispostback then
  if linkbutton just fired
    do this
  else
    do the form submit stuff
  end if
end if
 
Why not simply code the click event for the link button? That'l do donkey, that'l do
[bravo] Mark
If you are unsure of forum etiquette check here faq796-2540
 
I did that, didn't i? that still doesn't stop postback does it?
 
Sorry I skimmed the page and missed that top function. That is exactly what you did. I am no longer sure what you are asking for.

What is it that you are trying to accomplish? That'l do donkey, that'l do
[bravo] Mark
If you are unsure of forum etiquette check here faq796-2540
 
this is the best I can explain it:

I have a form... submit button causes the form to submit. However, there is another button that serves to only add a few controls to the page. This button is also submitting the form, which i don't want... so this little pseudo code snippet is really what i want to happen:

Code:
'if submitted
if page.ispostback then
  if addctlbutton just fired
    add some controls, don't submit form
  else
    do the form submit stuff
  end if
end if

does that make sense? I image sender is the actually the object that fired the event that is causing the postback, but I don't how to use/cast that object to be able to say &quot;yep, that was the button that was to add controls, not the submit button&quot;.

Sorry if this is confusing...
 
I think I know what your getting at now. I am not sure how to check that (I am not at my IDE right now) but I can see another way to do this. The do the form submit stuff code could be put into the click event for that button.

I often use the page_load event only to do things that I want to happen the first time page is accessed and none other by adding the if not ispostback statment around anything that happens. Then any other code goes into the event that I want it to happen under. If I have code that happens under more than one event I put it into a sub and run that same sub from each event handler, or should the events be of the same type add multiple handles... commands to the same handler.
So far I have yet to run across a situation where this doesn't work.

Hopefully I haven't confused you now. That'l do donkey, that'l do
[bravo] Mark
If you are unsure of forum etiquette check here faq796-2540
 
I think I see what you're saying... I'll give that a shot. Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top