input detection on the form submit?

   <form id="form1" runat="server">
<input type='submit' id='ID' runat='server' value='ID' /'>
<input type='submit' id='name' runat='server' value='name' />
<input type='submit' id='city' runat='server' value='city' />
</form>

On server callback, is there a way to intercept which submit is pressed?
note: Realize I do not want to add onclick and function name.
goodkAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Robb HillSenior .Net DeveloperCommented:
Yes ...create a function at pre render that checks the information of the control that caused the action.  brb with code for this.
0
Robb HillSenior .Net DeveloperCommented:
From the Page_Load event , you cant directly find control that caused the
postback. But if your control has autopostback property set to true . Then
there will be two hidden variable in your form __EVENTTARGET and
__EVENTARGUMENT which you can access in Page_Load event to get the control
name which caused the post back. __EVENTTARGET will have the object which
fired the post back event.

0
DesignbyonyxCommented:
Here's some code which implements robbhill's suggestion:

http://ryanfarley.com/blog/archive/2005/03/11/1886.aspx
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

goodkAuthor Commented:
http://ryanfarley.com/blog/archive/2005/03/11/1886.aspx
the above only detects asp:???  kind of controls.  Kindly, see my question again.  Do you think I may be doing something wrong?

        Response.Write(myGC.GetPostBackControl(this.Page));

and I created the function in my library myGC
When I click, asp kind of controls I get output, otherwise not.
please help - thanks
0
DesignbyonyxCommented:
Ah, misunderstood.  I won't get into asking you "why", but it seems like you are trying to do something fishy... and there might be a better solution.  I won't go there.

Try this:

<input type='submit' id='ID' runat='server' value='ID' onclick="doPostBack('ID', ''); /'>
<input type='submit' id='name' runat='server' value='name' onclick="doPostBack('name', ''); />
<input type='submit' id='city' runat='server' value='city' onclick="doPostBack('city', ''); />
0
goodkAuthor Commented:
Designbyonyx: nothing fishy! I iterate a through database and create a table with the fields as in the table.  

do not want to use Gridview. HTML tags are a very simple things - ASP just makes it overly complicated creating large overheads.

Please read my question, if you know an answer please write - I am still looking for help.

robbhill: Can you kindly give me example? thanks
0
goodkAuthor Commented:
see http://www.javascript-coder.com/html-form/html-form-submit.phtml

It is as simple in php, why I cannot do the same in asp.net??????

<input type="submit" name="Operation" value="Insert">  

<input type="submit" name="Operation" value="Update">

The server side code goes like this (PHP code):

if($_REQUEST['Operation'] == 'Update')  

{  

  //Do update here..  

}  

else

if($_REQUEST['Operation'] == "Insert")  

{  

  //Do insert here  

}

0
goodkAuthor Commented:
       Response.Write(" press button =  " + Request["ID"]);

That is all I did and it works!!
0
mohammad827Commented:
Normally only the value of the submit button that has been clicked gets posted only. So If you access
Request.form("ID") then you will get its value "ID" only if you have submitted using that button else you will get empty value.
0
goodkAuthor Commented:
I had hoped, that there was a way to iterate through all the buttons.  But it is ok, as I can call my database and read all the possible buttons I am setting.  I will append the name with a significant character so there is no confusion.

Not sure, that is the best approach but I think I can make it work.  If some one has better ideas please let me know. thanks
0
goodkAuthor Commented:
would something like this would work? how in c#, asp.net? thanks
'Method 1 - Form Count Method
Dim x
For x = 1 to Request.Form.Count
    Response.Write Request.Form.Key(x) & ": "
    Response.Write Request.Form.Item(x) & "<br />"
Next

'Method 2 - Field Object Method
Dim fldName
For Each fldName in Request.Form
    Response.Write fldName & ": " & _
    Request.Form(fldName) & "<br />"
Next
0
Robb HillSenior .Net DeveloperCommented:
You can iterate through all the buttons as well as every control that is rendered on the page as they themselves are stored in collection.  for example the implementation of a find control method will find a control by name but it will also write them all to a screen in a recursive loop...and you could skip control types in an if statement within the loop.
0
goodkAuthor Commented:
I tried the following and it worked-
        foreach (string fldName in Request.Form)
{
    Response.Write( fldName + ": " + Request.Form[fldName] + "<br />");
}
0
DesignbyonyxCommented:
If you want PHP functionality, use PHP.  I am a developer who started in PHP and moved to .NET... and I agree that .NET makes certain simple tasks extremely difficult.  But on the other hand, it makes most tasks extremely easy and scalable... but only if you leverage the controls provided by the .NET framework.

While .NET controls require a little overhead... I have built huge applications with hundreds of .NET controls on a page, and the page rendered fast... even under load.  When I said you were doing something "fishy" I purely meant that you are trying to use .NET in a way that it's not built to be used.  You should be creating proper handlers for click events.  If you are going to rely on the REQUEST object to handle postbacks... have fun.  The method you are planning on using will not scale... and it will annoy any developer who has to come after you.  It could also open up security holes in your application.
0
Robb HillSenior .Net DeveloperCommented:
this should do it and iterate through all buttons only making cntrlID the value of the button causing postback.
Dim ctrlname = Page.Request.Params("__EVENTTARGET")
                Dim control As Control = Nothing


                If Not (ctrlname) = Nothing Or Not (ctrlname) = String.Empty Then
                    control = Page.FindControl(ctrlname)
                Else
                    Dim ctl As String

                    For Each ctl In Page.Request.Form

                        Dim c As New Control
                        c = Page.FindControl(ctl)
                        If TypeOf c Is System.Web.UI.WebControls.Button Then
                            control = c

                        End If
                    Next
                End If
                Dim cntrlID As String = control.ID

Open in new window

0
goodkAuthor Commented:
To Designbyonyx:

If it was not for c#, compile and database connectivity I would have never touched asp.net.

It is extremely, slow, tedious and non-scalable and useless.

It appear to me that MS has tried to monopolize on simple html.  html is pre-programmed for the browser.  One only needs a way to prepare a page and recieve postback and interpret.  It is very simple.

asp.net does not provide any more security than the server security itself.

I found, Gridview incomplete and cumbersome.  I found login control very confusing.  I have spent a long time trying to use it but every time I wanted to something new I had to spent a long time to understand it.  Why even they had to create these controls?  All they had to do was show examples how the Grid can be written or how login can be written using their tool.

It took me few hours to create my own Login control and they are absolutly scalable.  I can copy my library to a new project and just call it.

Further, I found there is no convenient way to interact with Microsoft and get their help.  The help files and examples are unorganized.

I have wasted a lot of time on asp.net.  

Anyway,  what I am saying is only my opinion!! Obviously, I also respect your input.



0
DesignbyonyxCommented:
I totally hear you dude.  You sound like me when I started using .NET.  I switched to .NET purely because of a job I took several years ago... and now most everything I do is in .NET.

Coming from PHP, I hated how convoluted and "Microsoft" everything felt with .NET.  In particular, I missed being able to open Notepad and edit code (like I did with PHP).  With PHP, I could fix a bug and deploy my patch from my grandmother's computer.  There's no way you could do that with .NET.  But I have found that if you can embrace the development patterns and best practices for .NET, you can build extremely fast and scalable sites.  So I have to disagree with your comment about it being slow, non-scalable, and useless.  However, I agree 100% that it is tedious and cumbersome to perform some very simple tasks.  The learning curve is extremely long... which is a turnoff for people switching from other technologies.
0
goodkAuthor Commented:
Designbyonyx: I may agree with you just because I do not have a lot of experience with asp.net yet.

Anyway on my initial question, see my first post, as I learned it was a 1-step solution.  I named four controls the same and when the user pressed any of the button I was able to intercept by value what button they pressed.  No loops - very simple.

Not sure yet if every browser will give me same result.  I will check.

Hey, but I do really appreciate the discussion and your time.  

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Robb HillSenior .Net DeveloperCommented:
Your question was answered ...I must object as it is courtesy to give points to those who help you.
0
goodkAuthor Commented:
robbhill:  Hi - you did answer the question but it was quite late - I really feel bad myself that I could not give any poiints to any one.  I am sorry but it is a right thing to do.
0
DesignbyonyxCommented:
@robbhill - you and I gave the same solution in different languages.  It was not the solution he was wanting because he was not using .NET web controls... so neither of our solutions work.  While there was great advice given by both you and me, we do not deserve any points because we did not help solve the problem at hand.
0
goodkAuthor Commented:
none of the responses by the experts resolved the issue
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
HTML

From novice to tech pro — start learning today.