I am using MSHTML to automate oen workflow involved Angular. I am able to add the value in text box but somehow underline function doesn't get call and hence I get unwanted result.
below is the sample:
objIHTMLElement = doc.getElementById("email");
objIHTMLElement.setAttribute("value", "sas#abc.com");
html looks as below:
<div class="inpt-fld-err-msg-inline">
<input title="Email Add"
class="ng-valid ng-valid-maxlength ng-touched ng-dirty ng-empty"
id="email" aria-invalid="false" type="text" maxlength="50"
ng-change="save(SearchParams)"
ng-model="SearchParams.userProfil" autocomplete="off">
</div>
is there any way to do it using C#?
Regards,
Ajit
You can register and call you javascript method by passing appropriate parameters via following syntax from C#:
Page.ClientScript.RegisterStartupScript(this.GetType(),"CallMyFunction","save(" + SearchParams + )",true);
Kindly refer to this post: Calling JavaScript Function From CodeBehind
Related
I have:
<input name="input4" type="text" id="input4" disabled="disabled" class="jsx-3771882255" data-id="0">
I want get data of data-id by C#;
string s=input4.Attributes["data-id"].ToString(); //(can'tuse this!)
You have the disabled attribute set on your text box, this will not get submitted to the server, use the readonly attribute instead of the disabled attribute.
#vuong quang - Can you check my code and implement it's working for me and also I shared my code with a screenshot.
HTML Code
Add runat="server"
<input type="text" name="name" value="0" data-id="101" runat="server" id="txtvalue" />
HTML Code
Code behind
string id = txtvalue.Attributes["data-id"].ToString();
Check below screenshots
CS Page Code
I'm creating a datetime picker using code
<div class='input-group date'>
<input type='text' class="form-control" id='datetimepicker'/>
</div>
<script type="text/javascript">
$(function () {
$('#datetimepicker').datetimepicker({
viewMode: 'years'
});
});
</script>
which allows me to create a datetime input. For the backend code, I am able to add fields to the database for asp:textbok's, asp:labels etc, but not for this input.
Here is an example of others I am adding
cmd.Parameters.AddWithValue("#jobList", jobList.Text);
cmd.Parameters.AddWithValue("#jobCriteria", jobCriterta.Text);
When I try to do this for datetime, the option for the ID=datetimepicker does not appear and I'm not able to add whatever datetime is in that input to the database.
Cheers in advance for any help I'm sure it's simple!
If you want to access an html control in the back end you need to give the attribute runat="server" along with the tag definition.
<input type='text' runat="server" class="form-control" id='datetimepicker'/>
Then change your script as like this:
$("#<%=datetimepicker.ClientID%>").datetimepicker({
viewMode: 'years'
});
After adding this to the tag you will get datetimepicker in the back end. and you can access it's value to do the rest of operations. and one more suggestion use .Parameters.Add() instead for Parameters.AddWithValue()
Replace the input tag with TextBox server control.
<asp:TextBox ID="datetimepicker" runat="server" ClientIDMode="Static" />
Remember to set ClientIDMode as "Static" to make sure jQuery code can find the textbox correctly. Then the backend C# code can also use this textbox as web control object.
There is a complex function written in jquery that runs if the href below is clicked by the user. Is there any way I can simulate this click in the code behind of the asp form? In other words, I need to "click" the href called "shipping_question_ID_product_received_as_ordered_link" from my code behind to prepopulate this input. Can anyone assist?
<div class="no"><label class="label-1" for="shipping_question_ID_product_received_as_ordered_not_acceptable">Not Acceptable</label></div>
<div class="yes"><label class="label-2" for="shipping_question_ID_product_received_as_ordered_acceptable">Acceptable</label></div>
<label class="universal-label"></label>
<input type="radio" id="shipping_question_ID_product_received_as_ordered_not_acceptable" name="shipping-question-ID-product-received-as-ordered" value="Not Acceptable" runat="server">
<input type="radio" id="shipping_question_ID_product_received_as_ordered_acceptable" name="shipping-question-ID-product-received-as-ordered" value="Acceptable" checked="true" runat="server">
#ArindamNayak had the right idea, but there may be issues with his implementation. If you add the below script to your code-behind, you will achieve what I believe is your desired result:
var autoRunScript = string.Format("<script>$(function() {{ $('#{0}').click(); }} );</script>", shipping_question_ID_product_received_as_ordered_link.ClientID);
Page.RegisterClientScriptBlock("keyClientBlock", autoRunScript);
The difference here is that without wrapping your $(link).click() in a ready handler, jQuery may not process the command correctly. Additionally, you have to be careful with the ID that you use as it could be modified to include containers.
You can use following.
string jScript;
jScript="<script>$('#linkid').click()</script>";
Page.RegisterClientScriptBlock("keyClientBlock",jScript);
So this will add a JS code block programatically to aspx and this JS will execute to click the a href ( having id = "linkid"
I'm a C#/VB developer trying to migrate away from aspx and web forms towards HTML.
I'm trying to do this:
HTML
<input type="radio" id="rb" runat="server" />
C#
DataTable dt = clsMyClass.GetItemTable();
rb.DataSource = dt;
rb.DataValueField = "ItemID";
rb.DataTextField = "ItemName";
rb.DataBind();
Thanks.
Ok, you can use the controls provided by the Microsoft ASP.NET Web Forms to control what and how the User interacts with the Application that you're providing him with.
Actaully what those controls provide you is that you Validate the data on the server side as well as client side. The keyword, runat="server" is used to tell the server that this Element should be handled on the Server.
If you want to redesign your application you can do that too. Instead of doing anything, just simply use your own Controls.
<input type="text" onchange="function()" />
In the JavaScript you can handle the events on that element.
function () {
/* some validations */
}
runat="server" is just to ensure that whenever the control's value is changed or any other particular functions are triggered the server would execute some method to take control of that.
Similarly, if you're not using Web Forms. You can create your own custom Controls and your own custom events to handle all the methods and events.
For example, if you have this control
<input type="text" name="myName" />
jQuery would be handy in this
$('input[name=myName]').change(function () {
alert('Hi, ' + $(this).value);
}
This way, once a user changes the value, he would get an alert for Hi, [name_of_user]. If I were to write Afzaal Ahmad Zeeshan, it would pop up
Hi, Afzaal Ahmad Zeeshan.
Now let's give the whole form control. Sample form is
<form method="post">
<input type="text" name="myName" />
<input type="text" name="id" />
<input type="submit" value="Submit" />
</form>
jQuery would be
$('form').submit(function () {
/* send data to server */
}
On the server side, handle those fields and then save them.
What are you trying to achieve? Are you trying to bind these elements with contents from your database or simply trying to add some text...
You can make a function in your codebehind to catch the data from your database and simply write it to your input controls by using response.write methods...
UPDATE
Hey!!! how about a function in codebehind like ....
public string getTheValueFromDataBase()
{
string abc = "";
abc = "text from database over here...";
return abc;
}
IN HTML PAGE
<input type="radio" /><%Response.Write(getTheValueFromDataBase()); %>
I want to get the value of my input tag into my C#.
<div id="datetimepicker2" class="input-append">
<input data-format="MM/dd/yyyy HH:mm:ss PP" type="text"></input>
<span class="add-on">
<i data-time-icon="icon-time" data-date-icon="icon-calendar">
</i>
</span>
</div>// what should we use here?
The value is set by the user of the page.
I did't understand which control value you want to get. But If you want to get input element value into the code behind, you need to set runat="server" attribute, because this is a simple html element not a Asp control.
Add runat="server" and id="your_id" and you should have access to them.
for example:
<input type="text" value="Username" class="input-text autoclear"
runat="server" id="myTextBox" />
than you can simply get value of input box like this:
string myStringFromTheInput = myTextBox.Value;
For more options please See here
Try this
Add name for your input type
<input data-format="MM/dd/yyyy HH:mm:ss PP" name="txtBox1" type="text"></input>
and try this way for get value in codebehind
string value=Request.Form["txtBox1"];
You can access all your submitted form data at server side by looking into the form Request object.
Ex. Request.Form["txtDate"] OR Request["txtDate"].
Naming the html elements makes easier to look into form collection for specified element.
If what you posted is your actual code, you have an extra space in your closing tag
</asp: TextBox>
Should be
</asp:TextBox>
and then txt_todata.text should work