Remove Submit Query From dynamically added Image Button - c#

I am working on c# website.in one of this page i need to add dynamically means by code side image button,but it shows submit query.So,now my question is how can i remove this submit query from dynamically added image button

I assume you are doing something like this to add ImageButton :
ImageButton imageButton = new ImageButton();
FileInfo fileInfo = new FileInfo(strFileName);
imageButton.ImageUrl = "~/img/abc.png";
imageButton.Width = Unit.Pixel(100);
imageButton.Height = Unit.Pixel(100);
I suggest you to set value attribute to empty string "" like this :
imageButton.Attributes["value"]="";
OR
imageButton.Attributes.Add("value", "");
Also refer to this stackoverflow post
Hope this helps !

Related

Identifying Dynamically created ImageButton click and its properties in Xamarin.forms

I have used Xamrin.forms.labs to create Imagebutton in shared code. Number of imagebuttons varies according to the number of elements in the list. My questions are
How can I identify which button is clicked? (I need the text of the Imagebutton for identification)
I have to change the image to Source_on.png on the first click of the image button and change back to Source.png on second click. (Just like select and unselect)
How can I acheive it??
The code I have used to create ImageButtons is given below.
StackLayout Holder = new StackLayout {
HorizontalOptions=LayoutOptions.FillAndExpand,
VerticalOptions=LayoutOptions.Center,
Orientation=StackOrientation.Horizontal,
Spacing=2,
};
foreach (var options in list)
{
var Icon = new ImageButton () {
Source=Source.png,
BackgroundColor=Xamarin.Forms.Color.Transparent,
HorizontalOptions=LayoutOptions.CenterAndExpand,
VerticalOptions=LayoutOptions.CenterAndExpand,
Orientation=Xamarin.Forms.Labs.Enums.ImageOrientation.ImageOnTop,
Text=labeltxt,
};
Icon.Clicked += OnSelected;
Holder.Children.Add (Icon );
}
}
Providing a helpful link or sample code will be really helpful..
Thanks in Advance..
It would help a lot if you share the code of your ImageButton.
That being said... if your ImageButton has a Command property it would also have a CommandParameter property. If it doesn't have that - make them.
You'd set the CommandParameter property with some ID and then bind the Command to the same code, such as
ImageButton icon = null;
icon = new ImageButton{
...
Command= new Command((tag)=>{
icon.Source = ImageSource.FromFile("...");// see other .FromXYZ methods too
},
CommandParameter="<your tag here>",
}
BUT... before you do all of that check out the Xamarin.Forms.Labs, there's an ImageButton there already and you can add that project from NuGet by searching for "Xamarin Forms Labs" in the package manager

How to retrieve text from a TextBox that was created programatically

Alright, so I have a form set up that contains a label and a button. When the button is pressed it creates several labels and and two textfields in a specific area.
I cannot for the life of me, figure out how to retrieve the text from those textfields and store it in a public string.
Any help would be wonderful and greatly appreciated.
Edit: As per request.
TextBox playertextbox = new TextBox();
playertextbox.Location = new Point(460, 200);
this.Controls.Add(playertextbox);
You can assign a name to the textbox and later use ControlCollection.Find to retrieve it
Try this
TextBox playertextbox = new TextBox();
playertextbox.Location = new Point(460, 200);
playertextbox.Name = "playertxtBox"; // Add some name
this.Controls.Add(playertextbox);
Then use the name in the button click handler or similar :
//Use that name to search here
TextBox playertextbox = ((TextBox) this.Controls.Find("playertxtBox",true)[0]);
string text = playertextbox.Text;

creating RadEditor dynamically asp.net

I want to add RadEditor dynamically. It is getting added to the page but as soon as postback occurs i get Multiple controls with the same ID 'EditorRibbonBarResourcesHolder' were found. Below is the code that i am using to add control dynamically.
RadEditor editor = new RadEditor();
editor.ID = "editor_" + itemTypeattribute.ItemAttributeID + rand.Next();
cellAttributeValue.Controls.Add(editor);
editor.DialogOpener.ID = "editor_dialopOpener_" + itemTypeattribute.ItemAttributeID;
editor.DialogOpener.Window.ID = "editor_dialopOpener_window_"+ ItemTypeattribute.ItemAttributeID;
editor.ClientIDMode = ClientIDMode.AutoID;
editor.EnableEmbeddedScripts = true;
editor.Height = 200;
Any help is appreciated. Thanks
Whenever I need to use a radeditor "dynamically" I have it on the page from the start with visible=false and then show it when I need it.

get the control with a certain name provided as a string in c#

i have the name of a control in a string and I want to manipulate the control, how do i turn the string into the current form instance of that control in c#?
e.g.
string controlName = "Button1";
What goes here?
button1.text = "Changed";
Thanks
Button button1 = (Button)this.Controls[controlName];
You need to look up the control in the controls collections, then cast it to the correct type. Is this in WPF , WinForms or ASP.Net?
Inside the form, you could write (c#)
this.Controls["Button1"].Text = "Changed";
I suppose, this could be the syntax in vb.net
Me.Controls("Button1").Text = "Changed"
EDIT: I don't know, if that would compile. #Binary Worrier is right
Button btn1 = this.Controls["Button1"] as Button;
btn1.Text = "Changed";

How to programmatically click on text input in WebBrowser using C#

I have opened a website using WebBrowser. Now I would like to programmatically click input text (textbox) field. I can not use focus because this website uses JS to unlock this field only if it's clicked and I've tried also this:
Object obj = ele.DomElement;
System.Reflection.MethodInfo mi = obj.GetType().GetMethod("click");
mi.Invoke(obj, new object[0]);
But it returns mi = null. How to do this so it will work?
Very similar to my answer on your other question.
Get an HtmlElement respresentative of your textbox, and call HtmlElement.InvokeMember("click") on it.
If you can, use:
webbrowser1.Navigate("javascript:document.forms[0].submit()")
or something similar. For me, it's been much easier and more accurate.
To fill-up a text field on a webpage:
string code ="";
code = code + "var MyVar=document.getElementById('tbxFieldNameOnWebPage');if(MyVar != null) MyVar.value = 'SOMEVALUE';";
domDocument.parentWindow.execScript(code, "JScript");
Then To Click a button on a webpage:
code = "";
code = "var SignupFree = document.getElementsByTagName('button')[1];";
code = (code + " SignupFree.click();");
domDocument.parentWindow.execScript(code, "JScript");
you can also use document.getElementById('buttonID'); instead of document.getElementsByTagName('button')[1]; but an id must be provided for this button on that particular webpage.
Use InvokeMethhod on HtmlElement or Browser.InvokeScript function.

Categories

Resources