Click here to Skip to main content
15,915,975 members
Home / Discussions / C#
   

C#

 
GeneralRe: Detect which keyboard has fired PreviewKeyDown Pin
openLG12-Jun-17 22:32
openLG12-Jun-17 22:32 
Questionform fill pdf file Pin
Member 1325361311-Jun-17 13:51
Member 1325361311-Jun-17 13:51 
AnswerRe: form fill pdf file Pin
OriginalGriff11-Jun-17 19:47
mveOriginalGriff11-Jun-17 19:47 
GeneralRe: form fill pdf file Pin
Pete O'Hanlon11-Jun-17 23:58
mvePete O'Hanlon11-Jun-17 23:58 
GeneralRe: form fill pdf file Pin
OriginalGriff12-Jun-17 2:03
mveOriginalGriff12-Jun-17 2:03 
AnswerRe: form fill pdf file Pin
ZurdoDev12-Jun-17 7:20
professionalZurdoDev12-Jun-17 7:20 
AnswerRe: form fill pdf file Pin
Ravi Bhavnani12-Jun-17 11:24
professionalRavi Bhavnani12-Jun-17 11:24 
QuestionProgramatically click a button using http POST request Pin
Prasadaknair10-Jun-17 8:14
Prasadaknair10-Jun-17 8:14 
Please help me... I am stuck up with http post using http request.

I have an asp.net applicaton which is hosted locally in IIS(http://localhost/TestWebPage/Default.aspx) and here is the markup for Default.aspx;

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>Test Web Page</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>

<script type="text/javascript">       

    function showImage() {
        alert('hi');
    }
</script>    
</head>
<body>  
<form id="imageForm" name="imageForm" method="post" action="Default.aspx" >
    <input type="text" name="showImage" value="false" />
    <input type="submit" name="refresh" value="submit" onclick="showImage();" />
</form>
</body>
</html>
My Default.aspx.cs ;

protected void Page_Load(Object Source, EventArgs E)
{
// contains no code
}   
I have a separate c# application which tries to simulate the button click of "refresh" via http post to Default.aspx, here is the code;

string url = "http://localhost/TestWebPage/Default.aspx";
string postDataStr = "showImage=true";
postDataStr += "&refresh=submit";

byte[] postData = Encoding.ASCII.GetBytes(postDataStr);

HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
req.ContentLength = postData.Length;
req.Proxy = WebRequest.DefaultWebProxy;

using (var reqStream = req.GetRequestStream())
{
    reqStream.Write(postData, 0, postData.Length);
}

HttpWebResponse response = (HttpWebResponse)req.GetResponse();
Stream responseStream = response.GetResponseStream();
StreamReader reader = new StreamReader(responseStream, Encoding.Default);
string pageContent = reader.ReadToEnd();

string status = ((HttpWebResponse)response).StatusDescription;

reader.Close();
responseStream.Close();
response.Close();
My aspx page is already opened in a chrome browser. When the above code is executed, I want the javascript alert in the showImage() function to be displayed in the Default.aspx page in the same browser window itself.

Unfortunately its not happening now... am I missing anything? or is there any good approach to simulate the button click using separate c#?

Please guide.

AnswerRe: Programatically click a button using http POST request Pin
Afzaal Ahmad Zeeshan10-Jun-17 10:19
professionalAfzaal Ahmad Zeeshan10-Jun-17 10:19 
AnswerRe: Programatically click a button using http POST request Pin
Richard Deeming12-Jun-17 1:51
mveRichard Deeming12-Jun-17 1:51 
Question404 error when implementing an API Pin
Sara Khan Kulkarni10-Jun-17 4:39
Sara Khan Kulkarni10-Jun-17 4:39 
AnswerRe: 404 error when implementing an API Pin
OriginalGriff10-Jun-17 4:54
mveOriginalGriff10-Jun-17 4:54 
AnswerRe: 404 error when implementing an API Pin
Richard MacCutchan10-Jun-17 5:04
mveRichard MacCutchan10-Jun-17 5:04 
AnswerRe: 404 error when implementing an API Pin
User 418025410-Jun-17 6:11
User 418025410-Jun-17 6:11 
GeneralRe: 404 error when implementing an API Pin
Eddy Vluggen10-Jun-17 6:30
professionalEddy Vluggen10-Jun-17 6:30 
AnswerRe: 404 error when implementing an API Pin
Yoqueuris13-Jun-17 4:46
Yoqueuris13-Jun-17 4:46 
QuestionVS2017 : selecting files, then applying search/replace ? Pin
BillWoodruff8-Jun-17 1:22
professionalBillWoodruff8-Jun-17 1:22 
AnswerRe: VS2017 : selecting files, then applying search/replace ? Pin
Richard Deeming8-Jun-17 1:36
mveRichard Deeming8-Jun-17 1:36 
GeneralRe: VS2017 : selecting files, then applying search/replace ? Pin
BillWoodruff8-Jun-17 2:35
professionalBillWoodruff8-Jun-17 2:35 
GeneralRe: VS2017 : selecting files, then applying search/replace ? Pin
Member 12639408-Jun-17 3:02
Member 12639408-Jun-17 3:02 
GeneralRe: VS2017 : selecting files, then applying search/replace ? Pin
BillWoodruff8-Jun-17 3:26
professionalBillWoodruff8-Jun-17 3:26 
GeneralRe: VS2017 : selecting files, then applying search/replace ? Pin
ZurdoDev8-Jun-17 5:57
professionalZurdoDev8-Jun-17 5:57 
GeneralRe: VS2017 : selecting files, then applying search/replace ? Pin
BillWoodruff8-Jun-17 8:22
professionalBillWoodruff8-Jun-17 8:22 
QuestionCondition of C#. Pin
Member 113461537-Jun-17 22:11
Member 113461537-Jun-17 22:11 
AnswerRe: Condition of C#. Pin
Richard MacCutchan7-Jun-17 22:39
mveRichard MacCutchan7-Jun-17 22:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.